1 module test1.midirout; 2 3 import std.conv : to; 4 5 import pixelperfectengine.concrete.window; 6 7 import pixelperfectengine.audio.base.config; 8 9 public class MIDIRouting : Window { 10 ListView listView0; 11 SmallButton button_add; 12 SmallButton button_remove; 13 SmallButton button_moveUp; 14 SmallButton button_moveDown; 15 SmallButton button_save; 16 17 ModuleConfig mcfg; 18 public this(ModuleConfig mcfg){ 19 super(Box(0, 0, 285, 235), "New Window"); 20 listView0 = new ListView(new ListViewHeader(16, [40 ,223], ["Tr. Num" ,"Module Name"]), null, "listView0", 21 Box(5, 20, 280, 210)); 22 listView0.editEnable = true; 23 button_add = new SmallButton("addB", "addA", "button_add", Box.bySize(5, 215, 16, 16)); 24 button_remove = new SmallButton("removeB", "removeA", "button_remove", Box.bySize(5 + 16, 215, 16, 16)); 25 button_moveUp = new SmallButton("upArrowB", "upArrowA", "button_moveUp", Box.bySize(5 + 32, 215, 16, 16)); 26 button_moveDown = new SmallButton("downArrowB", "downArrowA", "button_moveDown", Box.bySize(5 + 48, 215, 16, 16)); 27 button_save = new SmallButton("saveB", "saveA", "button_save", Box.bySize(5 + 80, 215, 16, 16)); 28 29 this.addElement(listView0); 30 this.addElement(button_add); 31 this.addElement(button_remove); 32 this.addElement(button_moveUp); 33 this.addElement(button_moveDown); 34 this.addElement(button_save); 35 36 button_add.onMouseLClick = &button_add_onClick; 37 button_remove.onMouseLClick = &button_remove_onClick; 38 button_moveUp.onMouseLClick = &button_moveUp_onClick; 39 button_moveDown.onMouseLClick = &button_moveDown_onClick; 40 button_save.onMouseLClick = &onSave; 41 42 this.mcfg = mcfg; 43 44 foreach (size_t i, uint key; mcfg.midiRouting) { 45 listView0 ~= new ListViewItem(16, [to!dstring(i), to!dstring(mcfg.modNames[key])], 46 [TextInputFieldType.None, TextInputFieldType.ASCIIText]); 47 } 48 } 49 50 protected void refreshOrder() { 51 for (int i ; i < listView0.numEntries ; i++) { 52 listView0[i][0].text.text = to!dstring(i); 53 } 54 listView0.refresh(); 55 } 56 57 protected void button_add_onClick(Event ev) { 58 listView0.insertAt(listView0.value >= 0 ? listView0.value : 0, 59 new ListViewItem(16, [""d, ""d], [TextInputFieldType.None, TextInputFieldType.ASCIIText])); 60 refreshOrder(); 61 } 62 63 protected void button_remove_onClick(Event ev) { 64 listView0.removeEntry(listView0.value); 65 refreshOrder(); 66 } 67 68 protected void button_moveUp_onClick(Event ev) { 69 if (listView0.value > 0) { 70 listView0.moveEntry(listView0.value, listView0.value - 1); 71 refreshOrder(); 72 } 73 } 74 75 protected void button_moveDown_onClick(Event ev) { 76 if (listView0.value < listView0.numEntries) { 77 listView0.moveEntry(listView0.value, listView0.value + 1); 78 refreshOrder(); 79 } 80 } 81 82 protected void onSave(Event ev) { 83 uint[] newRouting; 84 for (int i ; i < listView0.numEntries ; i++) { 85 newRouting ~= cast(uint)mcfg.getModuleNum(to!string(listView0[i][1].getText)); 86 } 87 mcfg.setMIDIrouting(newRouting); 88 this.close(); 89 } 90 }