summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaveHodder67 <dave.hodder@focusrite.com>2015-08-13 13:54:08 +0100
committerDaveHodder67 <dave.hodder@focusrite.com>2015-08-13 13:54:08 +0100
commit04e2b3c71bec78ccbc8732d24de86a3f37372c28 (patch)
tree985832948f2c154003ad6cf8160bbd61aa205f1c
parente314c84ab02ffe0fe47e616c2904df7984c5302f (diff)
downloadlaunchpad-polymaker-04e2b3c71bec78ccbc8732d24de86a3f37372c28.tar.gz
launchpad-polymaker-04e2b3c71bec78ccbc8732d24de86a3f37372c28.zip
adding MIDI for OSX simulator
-rw-r--r--.gitignore2
-rw-r--r--tools/osx/simulator-osx.c91
2 files changed, 92 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index db8171d..25208da 100644
--- a/.gitignore
+++ b/.gitignore
@@ -45,3 +45,5 @@ build
45*.xcscheme 45*.xcscheme
46 46
47tools/osx/simulator.xcodeproj/xcuserdata/davehodder.xcuserdatad/xcschemes/xcschememanagement.plist 47tools/osx/simulator.xcodeproj/xcuserdata/davehodder.xcuserdatad/xcschemes/xcschememanagement.plist
48
49*.xcbkptlist
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//////////////////////////////////////////////////////////////////////////
39static MIDIClientRef g_client = 0;
40static MIDIPortRef g_inDevPort = 0;
41static MIDIPortRef g_outDevPort = 0;
42static MIDIPortRef g_inVirtualPort = 0;
43static 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
92static 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
105static 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
85int main(int argc, char * argv[]) 160int 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;