diff options
Diffstat (limited to 'tools/osx/simulator-osx.c')
-rw-r--r-- | tools/osx/simulator-osx.c | 91 |
1 files changed, 90 insertions, 1 deletions
diff --git a/tools/osx/simulator-osx.c b/tools/osx/simulator-osx.c index abd25f9..2c0909b 100644 --- a/tools/osx/simulator-osx.c +++ b/tools/osx/simulator-osx.c | |||
@@ -33,6 +33,15 @@ | |||
33 | #include <stdio.h> | 33 | #include <stdio.h> |
34 | #include "app.h" | 34 | #include "app.h" |
35 | 35 | ||
36 | #include <CoreMIDI/CoreMIDI.h> | ||
37 | |||
38 | ////////////////////////////////////////////////////////////////////////// | ||
39 | static MIDIClientRef g_client = 0; | ||
40 | static MIDIPortRef g_inDevPort = 0; | ||
41 | static MIDIPortRef g_outDevPort = 0; | ||
42 | static MIDIPortRef g_inVirtualPort = 0; | ||
43 | static MIDIPortRef g_outVirtualPort = 0; | ||
44 | |||
36 | // ____________________________________________________________________________ | 45 | // ____________________________________________________________________________ |
37 | // | 46 | // |
38 | // Simulator "hal". This lets you exercise your device code without having to upload | 47 | // Simulator "hal". This lets you exercise your device code without having to upload |
@@ -80,11 +89,91 @@ static void sim_app_timer_event() | |||
80 | app_timer_event(); | 89 | app_timer_event(); |
81 | } | 90 | } |
82 | 91 | ||
92 | static void readProc(const MIDIPacketList *pktlist, void *readProcRefCon, void *srcConnRefCon) | ||
93 | { | ||
94 | // farm out the packet list entries | ||
95 | const MIDIPacket *packet = &pktlist->packet[0]; | ||
96 | for (int i=0; i < pktlist->numPackets; ++i) | ||
97 | { | ||
98 | // process the packet | ||
99 | |||
100 | // next | ||
101 | packet = MIDIPacketNext(packet); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | static int findLaunchapdPro() | ||
106 | { | ||
107 | // find the input hardware port | ||
108 | for (ItemCount i=0; i < MIDIGetNumberOfSources(); ++i) | ||
109 | { | ||
110 | MIDIEndpointRef endpoint = MIDIGetSource(i); | ||
111 | if (endpoint) | ||
112 | { | ||
113 | // get the endpoint name (always available) | ||
114 | CFStringRef endpointName = NULL; | ||
115 | if (noErr != MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &endpointName)) | ||
116 | { | ||
117 | return -1; | ||
118 | } | ||
119 | |||
120 | if (CFStringCompare(endpointName, CFSTR("Standalone Port"), kCFCompareCaseInsensitive) == 0) | ||
121 | { | ||
122 | // found it! open the endpoint. | ||
123 | if (noErr != MIDIInputPortCreate(g_client, CFSTR("In"), readProc, NULL, &g_inDevPort)) | ||
124 | { | ||
125 | return -1; | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | } | ||
130 | |||
131 | // now find the output | ||
132 | for (ItemCount i=0; i < MIDIGetNumberOfDestinations(); ++i) | ||
133 | { | ||
134 | MIDIEndpointRef endpoint = MIDIGetDestination(i); | ||
135 | if (endpoint) | ||
136 | { | ||
137 | // get the endpoint name (always available) | ||
138 | CFStringRef endpointName = NULL; | ||
139 | if (noErr != MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &endpointName)) | ||
140 | { | ||
141 | return -1; | ||
142 | } | ||
143 | |||
144 | if (CFStringCompare(endpointName, CFSTR("Standalone Port"), kCFCompareCaseInsensitive) == 0) | ||
145 | { | ||
146 | // found it! open the endpoint. | ||
147 | if (noErr != MIDIOutputPortCreate(g_client, CFSTR("Out"), &g_outDevPort)) | ||
148 | { | ||
149 | return -1; | ||
150 | } | ||
151 | } | ||
152 | } | ||
153 | } | ||
154 | |||
155 | return (g_inDevPort && g_outDevPort); | ||
156 | } | ||
157 | |||
83 | // ____________________________________________________________________________ | 158 | // ____________________________________________________________________________ |
84 | 159 | ||
85 | int main(int argc, char * argv[]) | 160 | int main(int argc, char * argv[]) |
86 | { | 161 | { |
87 | // open MIDI ports and wire them up | 162 | // open MIDI ports and wire them up |
163 | CFStringRef strName = CFStringCreateWithCString(NULL, "Launchpad Pro Simulator", kCFStringEncodingASCII); | ||
164 | if (noErr == MIDIClientCreate(strName, NULL, NULL, &g_client)) | ||
165 | { | ||
166 | CFRelease(strName); | ||
167 | } | ||
168 | else | ||
169 | { | ||
170 | return -1; | ||
171 | } | ||
172 | |||
173 | if (findLaunchapdPro()) | ||
174 | { | ||
175 | return -2; | ||
176 | } | ||
88 | 177 | ||
89 | // init the app | 178 | // init the app |
90 | sim_app_init(); | 179 | sim_app_init(); |
@@ -92,7 +181,7 @@ int main(int argc, char * argv[]) | |||
92 | // start the terrible busywaiting timer loop | 181 | // start the terrible busywaiting timer loop |
93 | for (;;) | 182 | for (;;) |
94 | { | 183 | { |
95 | 184 | break; | |
96 | } | 185 | } |
97 | 186 | ||
98 | return 0; | 187 | return 0; |