Jamoma API  0.6.0.a19
MIDISource.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup modularMIDI
4  *
5  * @brief create an virtual MIDI source
6  *
7  * @details MidiSource sends messages to any external devices @n
8  * It is a wrapper around several plateform-specific library. @n
9  *
10  * @author Theo Delahogue
11  *
12  * @copyright © 2014, GMEA (http://www.gmea.net) @n
13  * This code is licensed under the terms of the "New BSD License" @n
14  * http://creativecommons.org/licenses/BSD/
15  */
16 
17 #include "MIDISource.h"
18 
19 #if !defined(TT_PLATFORM_MAC)
20 MIDISource::MIDISource(MIDIPtr protocol, TTSymbol& application, TTPtr client) :
21 mProtocol(protocol),
22 mClient(client),
23 mApplication(application)
24 {
25  ;
26 }
27 #else
28 MIDISource::MIDISource(MIDIPtr protocol, TTSymbol& application, MIDIClientRef client) :
29 mProtocol(protocol),
30 mClient(client),
31 mApplication(application)
32 {
33 
34 }
35 #endif
36 
37 MIDISource::~MIDISource()
38 {
39 #if !defined(TT_PLATFORM_MAC)
40  ;// TODO
41 #else
42  MIDIEndpointDispose(mSource);
43 #endif
44 }
45 
46 TTErr MIDISource::setName(TTSymbol& newName)
47 {
48  if (newName != mName) {
49 
50  mName = newName;
51 
52  setRunning(NO);
53 
54  // instantiate the source
55 #if !defined(TT_PLATFORM_MAC)
56  ;// TODO
57 #else
58  MIDIEndpointDispose(mSource);
59 
60  // determine the default system character encoding before to encode the c string name
61  CFStringEncoding defaultEncoding = CFStringGetSystemEncoding();
62 
63  // create an output source
64  CFStringRef s_name = CFStringCreateWithCString(kCFAllocatorDefault, mName.c_str(), defaultEncoding);
65  OSStatus status = MIDISourceCreate(mClient, s_name, &mSource);
66  if (status != noErr) {
67  TTLogError("Could not create source : %d\n", (int)status);
68  return kTTErrGeneric;
69  }
70 #endif
71  }
72 
73  return kTTErrNone;
74 }
75 
76 TTErr MIDISource::setRunning(TTBoolean running)
77 {
78  if (running != mRunning) {
79 
80  mRunning = running;
81  }
82 
83  return kTTErrNone;
84 }
85 
86 TTErr MIDISource::sendMessage(TTAddress& address, const TTValue& value)
87 {
88  if (mRunning) {
89 
90  // TODO
91  }
92 
93  return kTTErrGeneric;
94 }
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
create an virtual MIDI source
The TTAddress class is used to represent a string and efficiently pass and compare that string...
Definition: TTAddress.h:29
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
void TTFOUNDATION_EXPORT TTLogError(TTImmutableCString message,...)
Platform and host independent method for posting errors.
Definition: TTBase.cpp:572
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
Definition: TTBase.h:344
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
No Error.
Definition: TTBase.h:343
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34