19 #define thisTTClass MIDI
20 #define thisTTClassName "MIDI"
21 #define thisTTClassTags "network, protocol, MIDI"
23 #define thisProtocolVersion "0.1"
24 #define thisProtocolAuthor "Theo de la Hogue"
25 #define thisProtocolGet NO
26 #define thisProtocolSet YES
27 #define thisProtocolListen NO
28 #define thisProtocolDiscover NO
29 #define thisProtocolDiscoverAll NO
31 extern "C" TT_EXTENSION_EXPORT
TTErr TTLoadJamomaExtension_MIDI(
void)
34 MIDI::registerClass();
45 PmError err = Pm_Initialize();
49 TTLogError(
"MIDI : error %ld from Pm_Initialize()", err);
55 #if !defined(TT_PLATFORM_MAC)
58 OSStatus status = MIDIClientCreate(CFSTR(
"PortMidi"), NULL, NULL, &mClient);
59 if (status != noErr) {
60 TTLogError(
"Could not initialize PortMidi client : %d\n", (
int)status);
70 MIDIInputPtr midiInput;
71 MIDIOutputPtr midiOutput;
74 mInputs.getKeys(applications);
77 applicationName = applications[i];
78 mInputs.lookup(applicationName, v);
79 midiInput = MIDIInputPtr(
TTPtr(v[0]));
85 mOutputs.getKeys(applications);
88 applicationName = applications[i];
89 mOutputs.lookup(applicationName, v);
90 midiOutput = MIDIOutputPtr(
TTPtr(v[0]));
96 #if !defined(TT_PLATFORM_MAC)
99 MIDIClientDispose(mClient);
109 if (!mOutputs.lookup(applicationName, v)) {
111 MIDIOutputPtr midiOutput = MIDIOutputPtr(
TTPtr(v[0]));
113 if (!midiOutput->sendMessage(address, value)) {
119 ActivityOutMessage(message);
135 ActivityInMessage(message);
139 if (applicationName == mLocalApplicationName)
140 return ReceiveSetRequest(kTTSymEmpty, address, value);
144 return ReceiveListenAnswer(applicationName, address, value);
149 const PmDeviceInfo* deviceInfo = NULL;
150 int deviceCount = Pm_CountDevices();
153 if (inputValue.
size() == 1) {
157 deviceType = inputValue[0];
159 if (deviceCount < 0) {
161 logError(
"Pm_CountDevices() returned 0x%x\n", deviceCount);
165 for (
TTInt32 i = 0; i < deviceCount; i++) {
167 deviceInfo = Pm_GetDeviceInfo(i);
169 if (deviceType ==
TTSymbol(
"inputs") && deviceInfo->input)
172 else if (deviceType ==
TTSymbol(
"outputs") && deviceInfo->output)
191 if (inputValue.
size() == 1) {
195 TTSymbol applicationName = inputValue[0];
199 ApplicationSelect(applicationName, v);
202 if (applicationName == mLocalApplicationName)
203 runDestination(applicationName);
205 runInput(applicationName);
208 if (applicationName == mLocalApplicationName)
209 runSource(applicationName);
211 runOutput(applicationName);
220 mApplicationParameters.getKeys(applications);
222 Run(applications[i], none);
230 MIDIDestinationPtr midiDestination = NULL;
235 if (mInputs.lookup(applicationName, v)) {
238 MIDIProtocol.
get(
"input", v);
245 #if !defined(TT_PLATFORM_MAC)
248 midiDestination =
new MIDIDestination(
this, applicationName, mClient);
250 err = midiDestination->setName(inputName);
254 delete midiDestination;
255 midiDestination = NULL;
259 mInputs.append(applicationName,
TTPtr(midiDestination));
265 midiDestination = MIDIDestinationPtr(
TTPtr(v[0]));
268 if (mApplicationParameters.lookup(applicationName, v)) {
271 delete midiDestination;
272 midiDestination = NULL;
273 mInputs.remove(applicationName);
278 if (midiDestination) {
280 midiDestination->setRunning(YES);
290 MIDIInputPtr midiInput = NULL;
295 if (mInputs.lookup(applicationName, v)) {
298 MIDIProtocol.
get(
"input", v);
305 midiInput =
new MIDIInput(
this, applicationName);
306 err = midiInput->setName(inputName);
315 mInputs.append(applicationName,
TTPtr(midiInput));
321 midiInput = MIDIInputPtr(
TTPtr(v[0]));
324 if (mApplicationParameters.lookup(applicationName, v)) {
329 mInputs.remove(applicationName);
336 midiInput->setRunning(YES);
346 MIDIOutputPtr midiOutput = NULL;
351 if (mOutputs.lookup(applicationName, v)) {
354 MIDIProtocol.
get(
"output", v);
361 midiOutput =
new MIDIOutput(
this, applicationName);
362 err = midiOutput->setName(outputName);
371 mOutputs.append(applicationName,
TTPtr(midiOutput));
377 midiOutput = MIDIOutputPtr(
TTPtr(v[0]));
380 if (mApplicationParameters.lookup(applicationName, v)) {
385 mOutputs.remove(applicationName);
392 midiOutput->setRunning(YES);
402 MIDISourcePtr midiSource = NULL;
407 if (mOutputs.lookup(applicationName, v)) {
410 MIDIProtocol.
get(
"output", v);
417 #if !defined(TT_PLATFORM_MAC)
420 midiSource =
new MIDISource(
this, applicationName, mClient);
422 err = midiSource->setName(outputName);
431 mOutputs.append(applicationName,
TTPtr(midiSource));
436 midiSource = MIDISourcePtr(
TTPtr(v[0]));
439 if (mApplicationParameters.lookup(applicationName, v)) {
444 mInputs.remove(applicationName);
451 midiSource->setRunning(YES);
465 if (inputValue.
size() == 1) {
469 TTSymbol applicationName = inputValue[0];
473 ApplicationSelect(applicationName, v);
476 if (applicationName == mLocalApplicationName)
477 stopDestination(applicationName);
479 stopInput(applicationName);
482 if (applicationName == mLocalApplicationName)
483 stopSource(applicationName);
485 stopOutput(applicationName);
494 mApplicationParameters.getKeys(applications);
496 Stop(applications[i], none);
504 MIDIDestinationPtr midiDestination = NULL;
508 if (!mInputs.lookup(applicationName, v)) {
510 midiDestination = MIDIDestinationPtr(
TTPtr(v[0]));
513 if (mApplicationParameters.lookup(applicationName, v)) {
516 delete midiDestination;
517 midiDestination = NULL;
518 mInputs.remove(applicationName);
522 if (midiDestination) {
524 midiDestination->setRunning(NO);
535 MIDIInputPtr midiInput = NULL;
539 if (!mInputs.lookup(applicationName, v)) {
541 midiInput = MIDIInputPtr(
TTPtr(v[0]));
544 if (mApplicationParameters.lookup(applicationName, v)) {
549 mInputs.remove(applicationName);
555 midiInput->setRunning(NO);
566 MIDIOutputPtr midiOutput = NULL;
570 if (!mOutputs.lookup(applicationName, v)) {
572 midiOutput = MIDIOutputPtr(
TTPtr(v[0]));
575 if (mApplicationParameters.lookup(applicationName, v)) {
580 mOutputs.remove(applicationName);
586 midiOutput->setRunning(NO);
597 MIDISourcePtr midiSource = NULL;
601 if (!mOutputs.lookup(applicationName, v)) {
603 midiSource = MIDISourcePtr(
TTPtr(v[0]));
606 if (mApplicationParameters.lookup(applicationName, v)) {
611 mOutputs.remove(applicationName);
617 midiSource->setRunning(NO);
694 return sendMessage(to, address, value);
TTErr sendMessage(const TTSymbol name)
TODO: Document this function.
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
#define TT_PROTOCOL_INITIALIZE
Declares all members needed by any protocol class.
We build a directory of TTNodes, and you can request a pointer for any TTNode, or add an observer to ...
The TTAddress class is used to represent a string and efficiently pass and compare that string...
Create and use Jamoma object instances.
size_type size() const noexcept
Return the number of elements.
void prepend(const TTValue &aValueToPrepend)
Insert another TTValue before the first element.
void append(const T &anElementValueToAppend)
Insert a single TTElement at the end.
void * TTPtr
A generic pointer.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
void TTFOUNDATION_EXPORT TTLogError(TTImmutableCString message,...)
Platform and host independent method for posting errors.
void get(const TTUInt16 index, T &returnedElementValue) const
DEPRECATED.
std::int32_t TTInt32
32 bit signed integer
the MIDI protocol for Jamoma Modular
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
std::uint32_t TTUInt32
32 bit unsigned integer
#define TT_PROTOCOL_CONSTRUCTOR
Declares instantiation and registration methods to add the protocol class as any TTObject class...
#define addAttributeAsProtocolParameter(name, type)
Add a protocol parameter as an attribute of the class.
[doxygenAppendixC_copyExample]
unsigned char TTUInt8
8 bit unsigned integer (char)