1 module app;
2 
3 import dlangui;
4 
5 mixin APP_ENTRY_POINT;
6 
7 
8 import core.sys.windows.windows;
9 
10 import soundtab.ui.frame;
11 
12 //version = TestMidi;
13 version(TestMidi) {
14     import wasapi.midi;
15 
16     void testMidi() {
17         import core.thread;
18         MidiProvider midi = new MidiProvider();
19         Log.d("Testing MIDI interface");
20         Log.d("MIDI Input devices:", midi.inputDevCount, " output devices:", midi.outDevCount);
21         MidiOutDeviceDesc desc = midi.getOutputDevice();
22         MidiOutDevice midiout = desc.open;
23         if (!midiout) {
24             Log.e("Cannot open midi out device");
25             return;
26         }
27         midiout.sendEvent(0xC0, 1); // program change
28         midiout.sendEvent(0x90, 0x39, 0x4F); // note on A3
29         Thread.sleep(1500.dur!"msecs");
30         midiout.sendEvent(0x99, 38, 0x7F); // snare drum
31         midiout.sendEvent(0x80, 0x39, 0x7F); // note off A3
32         midiout.sendEvent(0x90, 0x3B, 0x4F); // note on A3
33         Thread.sleep(1500.dur!"msecs");
34         midiout.sendEvent(0x80, 0x3B, 0x7F); // note off A3
35         Thread.sleep(500.dur!"msecs");
36         midiout.sendEvent(0x89, 38, 0x7F); // off
37         midiout.close();
38     }
39 
40 }
41 
42 //version = DumpPulse;
43 
44 
45 version(DumpPulse)
46 void convertRaw(string filename) {
47     import std.file;
48     import std.conv : to;
49     short[] data = cast(short[])read(filename);
50     char[] buf;
51     char[] buf2;
52     buf ~= "    ";
53     for (int i = 0; i < data.length; i++) {
54         buf ~= to!string((cast(int)data[i]));
55         buf2 ~= to!string((cast(int)data[i]));
56         buf ~= ", ";
57         if (i % 16 == 15)
58             buf ~= "\n    ";
59         buf2 ~= "\n";
60     }
61     buf ~= "\n";
62     write(filename ~ ".d", buf);
63     write(filename ~ ".csv", buf2);
64 }
65 
66 /// entry point for dlangui based application
67 extern (C) int UIAppMain(string[] args) {
68 
69     auto hr = CoInitialize(null);
70     if (hr)
71         Log.e("CoInitialize failed");
72 
73     //initAudio();
74     version(DumpPulse) {
75         convertRaw("impuls20.raw");
76     }
77 
78     version(TestMidi) {
79         import wasapi.midi;
80         testMidi();
81     }
82 
83     /*
84     import soundtab.audio.loader;
85     WaveFile wav = loadSoundFile("jmj-chronologie3.mp3", true);
86     if (!wav)
87         Log.d("Sound file loaded ok");
88     else
89         Log.d("Error loading sound file");
90     */
91     // embed resources listed in views/resources.list into executable
92     embeddedResourceList.addResources(embedResourcesFromList!("resources.list")());
93 
94     Platform.instance.uiTheme = "theme_dark";
95     // create window
96     Log.d("Creating window");
97     import dlangui.platforms.windows.winapp;
98     Win32Window window = cast(Win32Window)Platform.instance.createWindow("SoundTab - Wacom Tablet Theremin", null, WindowFlag.Resizable, 800, 700);
99     Log.d("Window created");
100     import soundtab.ui.noteutil;
101     buildNoteConversionTable();
102 
103 
104     // create some widget to show in window
105     //window.mainWidget = (new Button()).text("Hello, world!"d).margins(Rect(20,20,20,20));
106     new SoundFrame(window);
107 
108     window.windowIcon = drawableCache.getImage("dlangui-logo1");
109 
110     // show window
111     window.show();
112 
113     // run message loop
114     return Platform.instance.enterMessageLoop();
115 }