1 module test1.modulerouter; 2 3 import pixelperfectengine.concrete.window; 4 import pixelperfectengine.audio.base.config; 5 6 import test1.app; 7 import test1.editorevents; 8 9 import std.conv : to; 10 11 public class ModuleRouter : Window { 12 ListView listView_modules; 13 ListView listView_routing; 14 Button button_addMod; 15 Button button_remMod; 16 Button button_preset; 17 Button button_sampleman; 18 Button button_audNode; 19 Button button_midiRout; 20 Button button_remNode; 21 AudioDevKit adk; 22 public this(AudioDevKit adk){ 23 super(Box(0, 16, 640, 480), "Modules and Routing"); 24 listView_modules = new ListView(new ListViewHeader(16, [256, 256], ["Type", "Name"]), null, "listView_modules", 25 Box(5, 20, 530, 175)); 26 listView_routing = new ListView(new ListViewHeader(16, [256, 256], ["From", "To"]), null, "listView_routing", 27 Box(5, 180, 530, 455)); 28 button_addMod = new Button("Add module..."d, "button_addMod", Box(535, 20, 635, 40)); 29 button_remMod = new Button("Remove module"d, "button_remMod", Box(535, 45, 635, 65)); 30 button_preset = new Button("Presets..."d, "button_preset", Box(535, 70, 635, 90)); 31 button_sampleman = new Button("Samples..."d, "button_samples", Box(535, 95, 635, 115)); 32 button_audNode = new Button("Add audio node"d, "button_audNode", Box(535, 180, 635, 200)); 33 //button_midiNode = new Button("Add MIDI node"d, "button1", Box(535, 205, 635, 225)); 34 button_remNode = new Button("Remove node"d, "button_remNode", Box(535, 205, 635, 225)); 35 button_midiRout = new Button("Set MIDI..."d, "button_midiRout", Box(535, 230, 635, 250)); 36 button_addMod.onMouseLClick = &button_addMod_onClick; 37 button_audNode.onMouseLClick = &button_addNode_onClick; 38 button_preset.onMouseLClick = &button_preset_onClick; 39 button_sampleman.onMouseLClick = &button_sampleman_onClick; 40 button_midiRout.onMouseLClick = &button_midiRout_onClick; 41 listView_modules.editEnable = true; 42 listView_modules.onTextInput = &listView_modules_onTextEdit; 43 listView_modules.onItemSelect = &listView_modules_onItemSelect; 44 listView_routing.editEnable = true; 45 listView_routing.multicellEditEnable = true; 46 listView_routing.onTextInput = &listView_routing_onTextEdit; 47 addElement(listView_modules); 48 addElement(listView_routing); 49 addElement(button_addMod); 50 addElement(button_remMod); 51 addElement(button_sampleman); 52 addElement(button_preset); 53 addElement(button_audNode); 54 addElement(button_midiRout); 55 addElement(button_remNode); 56 57 this.adk = adk; 58 refreshRoutingTable(); 59 refreshModuleList(); 60 } 61 public void refreshRoutingTable() { 62 ModuleConfig mcfg = adk.mcfg; 63 string[2][] routingTable = mcfg.getRoutingTable; 64 listView_routing.clear(); 65 foreach (string[2] key; routingTable) { 66 listView_routing ~= new ListViewItem(16, [key[0].to!dstring, key[1].to!dstring], 67 [TextInputFieldType.ASCIIText, TextInputFieldType.ASCIIText]); 68 } 69 listView_routing.refresh(); 70 } 71 public void refreshModuleList() { 72 ModuleConfig mcfg = adk.mcfg; 73 string[2][] moduleList = mcfg.getModuleList; 74 listView_modules.clear(); 75 foreach (string[2] key; moduleList) { 76 listView_modules ~= new ListViewItem(16, [key[0].to!dstring, key[1].to!dstring,], 77 [TextInputFieldType.None, TextInputFieldType.ASCIIText]); 78 } 79 } 80 private void listView_modules_onItemSelect(Event e) { 81 ListViewItem item = cast(ListViewItem)e.aux; 82 if (item[1].getText != "Rename me!") { 83 ModuleConfig mcfg = adk.mcfg; 84 adk.selectedModID = item[1].getText.to!string; 85 adk.selectedModule = mcfg.getModule(adk.selectedModID); 86 } 87 } 88 private void button_addMod_onClick(Event e) { 89 handler.addPopUpElement(new PopUpMenu([new PopUpMenuElement("qm816", "QM816"), new PopUpMenuElement("pcm8", "PCM8"), 90 new PopUpMenuElement("delaylines1010", "DelayLines:1024/1024"), 91 new PopUpMenuElement("delaylines1012", "DelayLines:1024/4096"), 92 new PopUpMenuElement("delaylines1212", "DelayLines:4096/4964"), 93 ], "moduleSelector", &onModuleTypeSelect)); 94 } 95 private void button_preset_onClick(Event e) { 96 adk.openPresetEditor(); 97 } 98 private void onModuleTypeSelect(Event e) { 99 MenuEvent me = cast(MenuEvent)e; 100 listView_modules ~= new ListViewItem(16, [me.itemSource.to!dstring, "Rename me!"], 101 [TextInputFieldType.None, TextInputFieldType.ASCIIText]); 102 listView_modules.refresh(); 103 //adk.eventStack.addToTop(new AddModuleEvent(adk.mcfg, me.itemSource, me.itemSource)); 104 } 105 private void button_addNode_onClick(Event e) { 106 listView_routing ~= new ListViewItem(16, ["!NONE!", "!NONE!"], 107 [TextInputFieldType.ASCIIText, TextInputFieldType.ASCIIText]); 108 listView_routing.refresh(); 109 } 110 private void button_sampleman_onClick(Event e) { 111 import test1.sampleman; 112 adk.wh.addWindow(new SampleMan(adk)); 113 } 114 private void listView_modules_onTextEdit(Event e) { 115 //CellEditEvent ce = cast(CellEditEvent)e; 116 ListViewItem item = cast(ListViewItem)e.aux; 117 adk.eventStack.addToTop(new AddModuleEvent(adk.mcfg, item[0].getText().to!string, item[1].getText().to!string)); 118 } 119 private void button_midiRout_onClick(Event ev) { 120 import test1.midirout; 121 handler.addWindow(new MIDIRouting(adk.mcfg)); 122 } 123 private void listView_routing_onTextEdit(Event e) { 124 ListViewItem item = cast(ListViewItem)e.aux; 125 if (item[0].getText != "!NONE!" && item[1].getText != "!NONE!") { 126 adk.eventStack.addToTop(new AddRoutingNodeEvent(adk.mcfg, item[0].getText().to!string, item[1].getText().to!string)); 127 } 128 } 129 }