diff options
author | DaveHodder67 <dave.hodder@focusrite.com> | 2015-08-13 17:52:01 +0100 |
---|---|---|
committer | DaveHodder67 <dave.hodder@focusrite.com> | 2015-08-13 17:52:01 +0100 |
commit | cf8238c77d58bda120525c9e4614a9f7971ef59a (patch) | |
tree | b7529114adc4aebddc8d7e3522e2bc8707b1f951 /tools | |
parent | 7c6fbef9abe3d75099f36e174a6f4dfd67eeaccc (diff) | |
download | launchpad-polymaker-cf8238c77d58bda120525c9e4614a9f7971ef59a.tar.gz launchpad-polymaker-cf8238c77d58bda120525c9e4614a9f7971ef59a.zip |
working MIDI surface on OS X
Diffstat (limited to 'tools')
-rw-r--r-- | tools/osx/simulator-osx.c | 109 |
1 files changed, 54 insertions, 55 deletions
diff --git a/tools/osx/simulator-osx.c b/tools/osx/simulator-osx.c index 046fdf8..38fa4dd 100644 --- a/tools/osx/simulator-osx.c +++ b/tools/osx/simulator-osx.c | |||
@@ -39,8 +39,7 @@ | |||
39 | static MIDIClientRef g_client = 0; | 39 | static MIDIClientRef g_client = 0; |
40 | static MIDIPortRef g_inDevPort = 0; | 40 | static MIDIPortRef g_inDevPort = 0; |
41 | static MIDIPortRef g_outDevPort = 0; | 41 | static MIDIPortRef g_outDevPort = 0; |
42 | static MIDIPortRef g_inVirtualPort = 0; | 42 | static MIDIEndpointRef g_outDevEndpoint = 0; |
43 | static MIDIPortRef g_outVirtualPort = 0; | ||
44 | 43 | ||
45 | // ____________________________________________________________________________ | 44 | // ____________________________________________________________________________ |
46 | // | 45 | // |
@@ -50,12 +49,21 @@ static MIDIPortRef g_outVirtualPort = 0; | |||
50 | 49 | ||
51 | void hal_plot_led(u8 type, u8 index, u8 red, u8 green, u8 blue) | 50 | void hal_plot_led(u8 type, u8 index, u8 red, u8 green, u8 blue) |
52 | { | 51 | { |
53 | // wire this up to MIDI out... | 52 | // send this up the MIDI. Construct sysex: |
53 | unsigned char data[] = {0xF0, 0x00, 0x20, 0x29, 0x02, 0x10, 0x0B, index, red, green, blue, 0xF7}; | ||
54 | |||
55 | static const int MAX_OUTPUT_BUFFER_SIZE = 256; | ||
56 | |||
57 | MIDIPacketList packetLst; | ||
58 | MIDIPacket *packet = MIDIPacketListInit(&packetLst); | ||
59 | MIDIPacketListAdd(&packetLst, MAX_OUTPUT_BUFFER_SIZE, packet, 0, sizeof(data), data); | ||
60 | |||
61 | MIDISend(g_outDevPort, g_outDevEndpoint, &packetLst); | ||
54 | } | 62 | } |
55 | 63 | ||
56 | void hal_send_midi(u8 port, u8 status, u8 d1, u8 d2) | 64 | void hal_send_midi(u8 port, u8 status, u8 d1, u8 d2) |
57 | { | 65 | { |
58 | // send this up a virtual MIDI port? | 66 | // TODO: send this up a virtual MIDI port? |
59 | } | 67 | } |
60 | 68 | ||
61 | void hal_send_sysex(u8 port, const u8* data, u16 length) | 69 | void hal_send_sysex(u8 port, const u8* data, u16 length) |
@@ -63,49 +71,51 @@ void hal_send_sysex(u8 port, const u8* data, u16 length) | |||
63 | // as above, or just dump to console? | 71 | // as above, or just dump to console? |
64 | } | 72 | } |
65 | 73 | ||
66 | // ____________________________________________________________________________ | ||
67 | // | ||
68 | // App event wrappers - these just log to the console. Would be nice to wire | ||
69 | // these up to a MIDI input from the real Launchpad Pro! | ||
70 | // ____________________________________________________________________________ | ||
71 | |||
72 | static void sim_app_init() | ||
73 | { | ||
74 | app_init(); | ||
75 | } | ||
76 | |||
77 | static void sim_app_surface_event(u8 type, u8 index, u8 value) | ||
78 | { | ||
79 | app_surface_event(type, index, value); | ||
80 | } | ||
81 | |||
82 | static void sim_app_midi_event(u8 port, u8 status, u8 d1, u8 d2) | ||
83 | { | ||
84 | app_midi_event(port, status, d1, d2); | ||
85 | } | ||
86 | |||
87 | static void sim_app_timer_event() | ||
88 | { | ||
89 | app_timer_event(); | ||
90 | } | ||
91 | |||
92 | ////////////////////////////////////////////////////////////////////////// | 74 | ////////////////////////////////////////////////////////////////////////// |
93 | static void processPacket(const unsigned char *data, int length) | 75 | static void processPacket(const unsigned char *data, int length) |
94 | { | 76 | { |
77 | // parse MIDI (very naively) | ||
78 | unsigned char status = 0; | ||
79 | unsigned char d1 = 0xff; | ||
80 | |||
95 | while (length > 0) | 81 | while (length > 0) |
96 | { | 82 | { |
97 | printf("%2.2x ", *data++); | 83 | if (*data & 0x80) |
84 | { | ||
85 | status = *data; | ||
86 | } | ||
87 | else | ||
88 | { | ||
89 | // data | ||
90 | switch (status) | ||
91 | { | ||
92 | case 0x90: // pads | ||
93 | case 0xB0: // circular buttons | ||
94 | { | ||
95 | if (d1> 0x7F) | ||
96 | { | ||
97 | // await data 2 byte | ||
98 | d1 = *data; | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | // complete note message - send up to the app | ||
103 | app_surface_event(TYPEPAD, d1, *data); | ||
104 | d1 = 0xff; | ||
105 | } | ||
106 | } | ||
107 | break; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | ++data; | ||
98 | --length; | 112 | --length; |
99 | } | 113 | } |
100 | printf("\n"); | ||
101 | |||
102 | // recieve a pad or button press! | ||
103 | } | 114 | } |
104 | 115 | ||
105 | |||
106 | static void readProc(const MIDIPacketList *pktlist, void *readProcRefCon, void *srcConnRefCon) | 116 | static void readProc(const MIDIPacketList *pktlist, void *readProcRefCon, void *srcConnRefCon) |
107 | { | 117 | { |
108 | // farm out the packet list entries | 118 | // farm out the packets |
109 | const MIDIPacket *packet = &pktlist->packet[0]; | 119 | const MIDIPacket *packet = &pktlist->packet[0]; |
110 | for (int i=0; i < pktlist->numPackets; ++i) | 120 | for (int i=0; i < pktlist->numPackets; ++i) |
111 | { | 121 | { |
@@ -117,7 +127,7 @@ static void readProc(const MIDIPacketList *pktlist, void *readProcRefCon, void * | |||
117 | } | 127 | } |
118 | } | 128 | } |
119 | 129 | ||
120 | static int findLaunchapdPro() | 130 | static int findLaunchpadPro() |
121 | { | 131 | { |
122 | // find the input hardware port | 132 | // find the input hardware port |
123 | for (ItemCount i=0; i < MIDIGetNumberOfSources(); ++i) | 133 | for (ItemCount i=0; i < MIDIGetNumberOfSources(); ++i) |
@@ -169,6 +179,7 @@ static int findLaunchapdPro() | |||
169 | { | 179 | { |
170 | return -1; | 180 | return -1; |
171 | } | 181 | } |
182 | g_outDevEndpoint = endpoint; | ||
172 | } | 183 | } |
173 | } | 184 | } |
174 | } | 185 | } |
@@ -176,12 +187,6 @@ static int findLaunchapdPro() | |||
176 | return !(g_inDevPort && g_outDevPort); | 187 | return !(g_inDevPort && g_outDevPort); |
177 | } | 188 | } |
178 | 189 | ||
179 | static int createVirtualPorts() | ||
180 | { | ||
181 | // create local virtual Launchpad Pro ports | ||
182 | return 0; | ||
183 | } | ||
184 | |||
185 | // ____________________________________________________________________________ | 190 | // ____________________________________________________________________________ |
186 | 191 | ||
187 | int main(int argc, char * argv[]) | 192 | int main(int argc, char * argv[]) |
@@ -198,28 +203,22 @@ int main(int argc, char * argv[]) | |||
198 | return -1; | 203 | return -1; |
199 | } | 204 | } |
200 | 205 | ||
201 | if (findLaunchapdPro()) | 206 | if (findLaunchpadPro()) |
202 | { | 207 | { |
203 | // no Launchpad Pro connected | 208 | // no Launchpad Pro connected |
204 | return -2; | 209 | return -2; |
205 | } | 210 | } |
211 | |||
212 | // now start things up | ||
213 | app_init(); | ||
206 | 214 | ||
207 | if (createVirtualPorts()) | 215 | // start a terrible busywaiting timer loop |
208 | { | ||
209 | // unable to open virtual MIDI ports | ||
210 | return -3; | ||
211 | } | ||
212 | |||
213 | // init the app | ||
214 | sim_app_init(); | ||
215 | |||
216 | // start the terrible busywaiting timer loop | ||
217 | for (;;) | 216 | for (;;) |
218 | { | 217 | { |
219 | usleep(1000); | 218 | usleep(1000); |
220 | app_timer_event(); | 219 | app_timer_event(); |
221 | 220 | ||
222 | // tickle the runloop so we can recieve events | 221 | // run the runloop so we can receive MIDI events |
223 | while (kCFRunLoopRunHandledSource == CFRunLoopRunInMode(kCFRunLoopCommonModes, 0, true)); | 222 | while (kCFRunLoopRunHandledSource == CFRunLoopRunInMode(kCFRunLoopCommonModes, 0, true)); |
224 | } | 223 | } |
225 | 224 | ||