vvopensource
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Groups Pages
VVMIDINode.h
1 
2 #import <Cocoa/Cocoa.h>
3 #import <CoreMIDI/CoreMIDI.h>
4 #import <AudioToolbox/AudioToolbox.h>
5 #import "VVMIDIMessage.h"
6 
7 
8 
9 
10 extern BOOL _VVMIDIFourteenBitCCs; // NO by default. according to MIDI spec, CCs 32-64 are the LSBs of 14-bit values (CCs 0-31 are the MSBs). some controllers/apps don't support the spec properly, and expect these CCs to be 64 different (low-res) values. set this BOOL to NO if you want this fmwk to treat CCs 0-64 as 7-bit vals, in violation of the spec!
11 extern double _machTimeToNsFactor;
12 
13 
14 
15 @interface VVMIDINode : NSObject {
16  MIDIEndpointRef endpointRef; // the endpoint for this particular node
17  NSMutableDictionary *properties; // dict or source properties (just for the hell of it)
18  MIDIClientRef clientRef; // the client receives the data
19  MIDIPortRef portRef; // the port is owned by the client, and connects it to the endpoint
20  CAClockRef mtcClockRef;
21  CAClockRef bpmClockRef;
22 
23  NSString *name;
24  NSString *deviceName;
25  id delegate; // the delegate will be passed any data i receive
26  BOOL sender; // if it's a midi-sending endpoint, this will be YES
27  BOOL virtualSender; // whether or not the sender is locally owned
28  // make sure processing sysex can happen across multiple iterations of the callback loop
29  BOOL processingSysex;
30  int processingSysexIterationCount;
31  NSMutableArray *sysexArray; // received sysex data is added to this array. array is instance in node because a sysex dump may be split up across several MIDI packets, so we need something persistent...
32  // the node will always *process* midi, but it will only send/receive midi if 'enabled' is YES
33  BOOL enabled;
34 
35  int twoPieceCCVals[16][64]; // midi CCs 0-31 are the MSBs ("coarse") of values, and CCs 32-64 are the LSBs ("fine"). in order to reconstruct the full 32-bit value from either received piece, i need to store both "pieces" of it (for each channel). all the LSBs are set to -1 until an actual value is received: if the LSBs aren't being used, then the math changes subtly (7-bit 127 as 1.0 vs 7-bit MSB not being 1.0)
36 
37  // this mutex makes sure multiple threads sending to this node simultaneously don't collide
38  pthread_mutex_t sendingLock;
39 
40  // if i'm a sender, these variables are used to store a packet list
41  MIDIPacketList *packetList;
42  MIDIPacket *currentPacket;
43  Byte scratchStruct[4];
44 }
45 
46 - (id) initReceiverWithEndpoint:(MIDIEndpointRef)e;
47 - (id) initReceiverWithName:(NSString *)n;
48 - (id) initSenderWithEndpoint:(MIDIEndpointRef)e;
49 - (id) initSenderWithName:(NSString *)n;
50 
51 - (id) commonInit;
52 
53 - (void) loadProperties;
54 - (void) receivedMIDI:(NSArray *)a;
55 - (void) setupChanged;
56 
57 - (void) sendMsg:(VVMIDIMessage *)m;
58 - (void) sendMsgs:(NSArray *)a;
59 
60 - (BOOL) sender;
61 - (BOOL) receiver;
62 
63 - (MIDIEndpointRef) endpointRef;
64 - (NSMutableDictionary *) properties;
65 - (CAClockRef) mtcClockRef;
66 - (NSString *) name;
67 - (NSString *) deviceName;
68 - (NSString *) fullName;
69 - (id) delegate;
70 - (void) setDelegate:(id)n;
71 - (BOOL) processingSysex;
72 - (void) setProcessingSysex:(BOOL)n;
73 - (int) processingSysexIterationCount;
74 - (void) setProcessingSysexIterationCount:(int)n;
75 - (NSMutableArray *) sysexArray;
76 - (BOOL) enabled;
77 - (void) setEnabled:(BOOL)n;
78 - (void) _getValsForCC:(int)cc channel:(int)c toMSB:(int *)msb LSB:(int *)lsb;
79 - (void) _setValsForCC:(int)cc channel:(int)c fromMSB:(int)msb LSB:(int)lsb;
80 - (double) MTCQuarterFrameSMPTEAsDouble;
81 - (double) midiClockBeats;
82 - (double) midiClockBPM;
83 
84 @end
85 
86 void myMIDIReadProc(const MIDIPacketList *pktList, void *readProcRefCon, void *srcConnRefCon);
87 void myMIDINotificationProc(const MIDINotification *msg, void *refCon);
88 void senderReadProc(const MIDIPacketList *pktList, void *readProcRefCon, void *srcConnRefCon);
89 void clockListenerProc(void *userData, CAClockMessage msg, const void *param);