1 module sound_page; 2 3 import std.functional; 4 5 import awebview.wrapper; 6 import awebview.sound; 7 8 import awebview.gui.application; 9 import awebview.gui.activity; 10 import awebview.gui.html; 11 import awebview.gui.methodhandler; 12 import awebview.gui.widgets.button; 13 import awebview.gui.widgets.text; 14 import std.stdio; 15 16 class SoundPage : TemplateHTMLPage!(import(`sound_page.html`)) 17 { 18 this() 19 { 20 super("SoundPage", null); 21 _amp = new Amplifier; 22 _amp.amplitude = 1.0; 23 24 this ~= new InputButton!()("btn_snd").unaryFun!((a){ 25 a.staticProps["value"] = "Play"; 26 a.onClick.strongConnect((){ 27 _amp.amplitude = _txt_amp.text.to!float; 28 _chunk = SoundChunk.fromFile(_txt_snd.text); 29 _ch.play(_chunk); 30 }); 31 return a; 32 }); 33 34 this ~= new InputText!()("txt_snd").unaryFun!((a){ 35 _txt_snd = a; return a; 36 }); 37 38 this ~= new InputText!()("txt_amp").unaryFun!((a){ 39 _txt_amp = a; return a; 40 }); 41 } 42 43 44 override 45 void onStart(Activity activity) 46 { 47 super.onStart(activity); 48 this ~= application.to!SDLApplication.soundManager.newChannel("ch1").unaryFun!((a){ 49 _ch = a; return a; 50 }); 51 _ch.effector = _amp; 52 } 53 54 private: 55 InputText!() _txt_snd; 56 InputText!() _txt_amp; 57 SoundChunk _chunk; 58 SoundChannel _ch; 59 Amplifier _amp; 60 } 61 62 63 final class Amplifier 64 { 65 void applyEffect(uint ch, void[] stream) 66 { 67 short[] buf = cast(short[])stream; 68 foreach(ref e; buf) 69 e = cast(short)(e * _amp); 70 } 71 72 73 void done(uint ch) 74 { 75 76 } 77 78 79 void amplitude(float v) 80 { 81 _amp = v; 82 } 83 84 85 private: 86 float _amp; 87 }