Jamoma API  0.6.0.a19
TTMidiFormat.cpp
1 /*
2  * Object to format common types of MIDI events into raw MIDI event dictionaries
3  * Copyright © 2011, Timothy Place
4  *
5  * License: This code is licensed under the terms of the "New BSD License"
6  * http://creativecommons.org/licenses/BSD/
7  */
8 
9 #include "TTGraphObjectBase.h"
10 #include "TTMidiFormat.h"
11 #ifdef TT_PLATFORM_WIN
12 #include <algorithm>
13 #endif
14 
15 #define thisTTClass TTMidiFormat
16 #define thisTTClassName "midi.format"
17 #define thisTTClassTags "midi"
18 
19 
21 {
22  addMessageWithArguments(dictionary);
23 }
24 
25 
26 TTMidiFormat::~TTMidiFormat()
27 {
28  ;
29 }
30 
31 
32 TTErr TTMidiFormat::dictionary(const TTValue& input, TTValue& output)
33 {
34  TTDictionaryPtr d = NULL;
35  TTSymbol schema;
36 
37  //input.get(0, (TTPtr*)(&d));
38  d = TTDictionaryPtr(TTPtr(input[0]));
39 
40  schema = d->getSchema();
41 
42  if (schema == TT("MidiNoteEvent")) {
43  TTValue v;
44  TTUInt8 noteNumber = 0;
45  TTUInt8 noteVelocity = 0;
46  TTUInt8 noteChannel = 1;
47 
48  d->getValue(v);
49  noteNumber = v[0];
50  noteVelocity = v[1];
51  noteChannel = v[2];
52 
53  if (noteVelocity > 0) // Note-on
54  d->append(TT("status"), 143 + noteChannel);
55  else // Note-off
56  d->append(TT("status"), 127 + noteChannel);
57 
58  d->append(TT("data1"), noteNumber);
59  d->append(TT("data2"), noteVelocity);
60  d->setSchema(TT("RawMidiEvent"));
61  output[0] = TTPtr(d);
62  }
63  else if (schema == TT("RawMidiEvent"))
64  output = input; // Nothing to do...
65  else
66  return kTTErrInvalidType;
67 
68  return kTTErrNone;
69 }
70 
TTErr append(const TTSymbol aKey, const TTValue aValue)
Insert an item into the hash table.
Definition: TTDictionary.h:212
Bad DataType for the context.
Definition: TTBase.h:347
Jamoma Asynchronous Object Graph Layer.
TTErr getValue(T &aReturnedValue) const
Get the dictionary's primary value.
Definition: TTDictionary.h:202
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
A type that represents the key as a C-String and the value as a pointer to the matching TTSymbol obje...
Definition: TTDictionary.h:47
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
const TTSymbol getSchema() const
TODO: Add documentation.
Definition: TTDictionary.h:181
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:27
TTErr setSchema(const TTSymbol aSchemaName)
TODO: Add documentation schemaName TODO: Add documentation.
Definition: TTDictionary.h:172
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
TTDictionary * TTDictionaryPtr
[doxygenAppendixC_typedefExample]
Definition: TTDictionary.h:279
TT_OBJECT_CONSTRUCTOR
Constructor macro.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
unsigned char TTUInt8
8 bit unsigned integer (char)
Definition: TTBase.h:174