Jamoma API  0.6.0.a19
MIDI.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup modularMIDI
4  *
5  * @brief the MIDI protocol for Jamoma Modular
6  *
7  * @details
8  *
9  * @author Theo Delahogue
10  *
11  * @copyright © 2014, GMEA (http://www.gmea.net) @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 #ifndef __MIDI_H__
17 #define __MIDI_H__
18 
19 #include "TTProtocol.h"
20 #include "MIDIInclude.h"
21 #include "MIDIDestination.h"
22 #include "MIDIInput.h"
23 #include "MIDIOutput.h"
24 #include "MIDISource.h"
25 
26 class MIDIDestination;
27 typedef MIDIDestination* MIDIDestinationPtr;
28 
29 class MIDIInput;
30 typedef MIDIInput* MIDIInputPtr;
31 
32 class MIDIOutput;
33 typedef MIDIOutput* MIDIOutputPtr;
34 
35 class MIDISource;
36 typedef MIDISource* MIDISourcePtr;
37 
38 class MIDI : public TTProtocol {
39 
40  TTCLASS_SETUP(MIDI)
41 
42 private:
43 
44  TT_PROTOCOL_PARAMETER(Input); ///< PROTOCOL PARAMETER : each registered application have to setup its input device name
45  TT_PROTOCOL_PARAMETER(Output); ///< PROTOCOL PARAMETER : each registered application have to setup its output device name
46 
47  TTHash mInputs; ///< a table of MIDIInput instances for each device
48  TTHash mOutputs; ///< a table of MIDIOutput instances for each device
49 
50 #if !defined(TT_PLATFORM_MAC)
51  TTPtr mClient; ///< TODO : a client handle to the Windows MIDI server
52 #else
53  MIDIClientRef mClient; ///< a client handle to the Mac OS X Core MIDI server
54 #endif
55 
56 public:
57  /** send messages using MIDIOutput or MIDISource instances relative to an application
58  @param applicationName : #TTSymbol
59  @param address : #TTAddress
60  @param value : #TTValue
61  @return errorcode : #TTErr
62  */
63  TTErr sendMessage(TTSymbol& applicationName, TTAddress& address, const TTValue& value);
64 
65  /** used by MIDIInput and MIDIDestination instances to pass received messages
66  @param applicationName : #TTSymbol
67  @param address : #TTAddress
68  @param value : #TTValue
69  @return errorcode : #TTErr
70  */
71  TTErr receivedMessage(TTSymbol& applicationName, TTAddress& address, const TTValue& value);
72 
73 private:
74  /** Scan to find remote applications and add them to the application manager
75  @param inputValue : #TTSymbol "inputs" or #TTSymbol "outputs"
76  @param outputValue : all remote device names
77  @return errorcode : return a kTTErrGeneric if the protocol fails to start or if it was running already
78  */
79  TTErr Scan(const TTValue& inputValue, TTValue& outputValue);
80 
81  /*!
82  * Run MIDI sending and reception
83  @param inputValue : nothing to run all registered applications or a #TTSymbol application name
84  @param outputValue : nothing
85  @return errorcode : return a kTTErrGeneric if the protocol fails to start or if it was running already
86  */
87  TTErr Run(const TTValue& inputValue, TTValue& outputValue);
88  TTErr runDestination(TTSymbol& applicationName);
89  TTErr runInput(TTSymbol& applicationName);
90  TTErr runOutput(TTSymbol& applicationName);
91  TTErr runSource(TTSymbol& applicationName);
92 
93  /*!
94  * Stop MIDI sending and reception
95  @param inputValue : nothing to stop all registered applications or a #TTSymbol application name
96  @param outputValue : nothing
97  @return errorcode : return a kTTErrGeneric if the protocol fails to stop or if it was already stopped
98  */
99  TTErr Stop(const TTValue& inputValue, TTValue& outputValue);
100  TTErr stopDestination(TTSymbol& applicationName);
101  TTErr stopInput(TTSymbol& applicationName);
102  TTErr stopOutput(TTSymbol& applicationName);
103  TTErr stopSource(TTSymbol& applicationName);
104 
105  /**************************************************************************************************************************
106  *
107  * SEND REQUEST METHODS
108  *
109  **************************************************************************************************************************/
110 
111  /*!
112  * Send a discover request to an application to get a part of the namespace at the given address
113  *
114  @param to : the application where to discover
115  @param address : the address to discover
116  @param returnedType : the type of the node at the address (default is none which means no type)
117  @param returnedChildren : all names of nodes below the address
118  @param returnedAttributes : all attributes the node at the address
119  @param tryCount : number of try for this request
120  @return errorcode : kTTErrNone means the answer has been received, kTTErrValueNotFound means something is bad in the request
121  else it returns kTTErrGeneric if no answer or timeout
122  */
124  TTSymbol& returnedType,
125  TTValue& returnedChildren,
126  TTValue& returnedAttributes,
127  TTUInt8 tryCount=0);
128 
129  /*!
130  * Send a discover all request to an application to fill all the directory under this address
131  *
132  @param to : the application where to discover
133  @param address : the address to discover
134  @param node : the node for this address
135  @param tryCount : number of try for this request
136  @return errorcode : kTTErrNone means the answer has been received, kTTErrValueNotFound means something is bad in the request
137  else it returns kTTErrGeneric if no answer or timeout
138  */
140  TTNodePtr node,
141  TTUInt8 tryCount=0);
142 
143  /*!
144  * Send a get request to an application to get a value at the given address
145  *
146  @param to : the application where to get
147  @param address : the address to get
148  @param returnedValue : the value which is going to be filled
149  @param tryCount : number of try for this request
150  @return errorcode : kTTErrNone means the answer has been received, kTTErrValueNotFound means something is bad in the request
151  else it returns kTTErrGeneric if no answer or timeout
152  */
153  TTErr SendGetRequest(TTSymbol to, TTAddress address,
154  TTValue& returnedValue,
155  TTUInt8 tryCount=0);
156 
157  /*!
158  * Send a set request to set a value of a specific application
159  *
160  @param to : the application where to set
161  @param address : the address to set
162  @param value : anything to send
163  @param tryCount : number of try for this request
164  @return errorcode : kTTErrNone means the answer has been received, kTTErrValueNotFound means something is bad in the request
165  */
166  TTErr SendSetRequest(TTSymbol to, TTAddress address,
167  TTValue& value,
168  TTUInt8 tryCount=0);
169 
170  /*!
171  * Send a listen request to a specific application
172  *
173  @param to : the application where to listen
174  @param address : the address to listen
175  @param attribute : the attribute to listen
176  @param enable : enable/disable the listening
177  @param tryCount : number of try for this request
178  @return errorcode : kTTErrNone means the answer has been received, kTTErrValueNotFound means something is bad in the request
179  */
181  TTBoolean enable,
182  TTUInt8 tryCount=0);
183 
184 
185  /**************************************************************************************************************************
186  *
187  * SEND ANSWER METHODS
188  *
189  **************************************************************************************************************************/
190 
191  /*!
192  * Send a disover answer to a application which ask for.
193  *
194  @param to : the application where to send answer
195  @param address : the address where comes from the description
196  @param returnedType : the type of the node at the address (default is none which means no type)
197  @param returnedChildren : all names of nodes below the address
198  @param returnedAttributes : all attributes the node at the address
199  */
201  TTSymbol& returnedType,
202  TTValue& returnedChildren,
203  TTValue& returnedAttributes,
204  TTErr err=kTTErrNone);
205 
206  /*!
207  * Send a discover answer to a application which ask for.
208  *
209  @param to : the application where to send answer
210  @param address : the address where comes from the description
211  @param node : the node for this address
212  */
214  TTNodePtr node,
215  TTErr err=kTTErrNone);
216 
217  /*!
218  * Send a get answer to a application which ask for.
219  *
220  @param to : the application where to send answer
221  @param address : the address where comes from the value
222  @param returnedValue : the value of the attribute at the address
223  */
224  TTErr SendGetAnswer(TTSymbol to, TTAddress address,
225  const TTValue& returnedValue,
226  TTErr err=kTTErrNone);
227 
228  /*!
229  * Send a listen answer to a application which ask for.
230  *
231  @param to : the application where to send answer
232  @param address : the address where comes from the value
233  @param returnedValue : the value of the attribute at the address
234  */
236  const TTValue& returnedValue,
237  TTErr err=kTTErrNone);
238 };
239 typedef MIDI* MIDIPtr;
240 
241 #endif // __MIDI_H__
TTErr sendMessage(const TTSymbol name)
TODO: Document this function.
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
virtual TTErr Stop(const TTValue &inputValue, TTValue &outputValue)=0
create an virtual MIDI source
virtual TTErr SendDiscoverAllAnswer(TTSymbol to, TTAddress address, TTNodePtr node, TTErr err=kTTErrNone)=0
virtual TTErr SendGetRequest(TTSymbol to, TTAddress address, TTValue &returnedValue, TTUInt8 tryCount=0)=0
We build a directory of TTNodes, and you can request a pointer for any TTNode, or add an observer to ...
Definition: TTNode.h:59
The TTAddress class is used to represent a string and efficiently pass and compare that string...
Definition: TTAddress.h:29
TTProtocol is the base class for all protocol protocol.
Definition: TTProtocol.h:60
bind to an external device source
Maintain a collection of TTValue objects indexed by TTSymbol pointers.
Definition: TTHash.h:36
virtual TTErr SendListenAnswer(TTSymbol to, TTAddress address, const TTValue &returnedValue, TTErr err=kTTErrNone)=0
#define TTCLASS_SETUP(className)
TODO Doxygen: need more comments here.
Definition: TTFoundation.h:54
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
#define TT_PROTOCOL_PARAMETER(name)
Declares specific accessors methods to manage the parameter value in order to have one value per regi...
Definition: TTProtocol.h:43
create an virtual MIDI destination
A Protocol interface.
virtual TTErr SendListenRequest(TTSymbol to, TTAddress address, TTBoolean enable, TTUInt8 tryCount=0)=0
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
virtual TTErr SendDiscoverAllRequest(TTSymbol to, TTAddress address, TTNodePtr node, TTUInt8 tryCount=0)=0
virtual TTErr SendGetAnswer(TTSymbol to, TTAddress address, const TTValue &returnedValue, TTErr err=kTTErrNone)=0
virtual TTErr SendDiscoverRequest(TTSymbol to, TTAddress address, TTSymbol &returnedType, TTValue &returnedChildren, TTValue &returnedAttributes, TTUInt8 tryCount=0)=0
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
Includes and definitions for the MIDI protocol for Jamoma Modular.
virtual TTErr SendDiscoverAnswer(TTSymbol to, TTAddress address, TTSymbol &returnedType, TTValue &returnedChildren, TTValue &returnedAttributes, TTErr err=kTTErrNone)=0
No Error.
Definition: TTBase.h:343
virtual TTErr Scan(const TTValue &inputValue, TTValue &outputValue)=0
Scan to find remote applications and add them to the application manager.
virtual TTErr Run(const TTValue &inputValue, TTValue &outputValue)=0
bind to an external device destination
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
virtual TTErr SendSetRequest(TTSymbol to, TTAddress address, TTValue &value, TTUInt8 tryCount=0)=0
unsigned char TTUInt8
8 bit unsigned integer (char)
Definition: TTBase.h:174