/[svn]/linuxsampler/trunk/src/drivers/midi/VirtualMidiDevice.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/drivers/midi/VirtualMidiDevice.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1659 by schoenebeck, Sun Feb 3 00:13:27 2008 UTC revision 1896 by persson, Mon May 4 18:34:44 2009 UTC
# Line 16  Line 16 
16    
17  namespace LinuxSampler {  namespace LinuxSampler {
18    
19      struct _private_data_t {      struct VirtualMidiDevice::private_data_t {
20          atomic_t notesChanged; // whether some key changed at all          atomic_t notesChanged; // whether some key changed at all
21          atomic_t pNoteChanged[MIDI_KEYS]; // which key(s) changed          atomic_t pNoteChanged[MIDI_KEYS]; // which key(s) changed
22          atomic_t pNoteIsActive[MIDI_KEYS]; // status of each key (either active or inactive)          atomic_t pNoteIsActive[MIDI_KEYS]; // status of each key (either active or inactive)
23            atomic_t pNoteOnVelocity[MIDI_KEYS];
24            atomic_t pNoteOffVelocity[MIDI_KEYS];
25          RingBuffer<VirtualMidiDevice::event_t,false> events;          RingBuffer<VirtualMidiDevice::event_t,false> events;
26    
27          _private_data_t() : events(MAX_EVENTS, 0) {}          private_data_t() : events(MAX_EVENTS, 0) {}
28      };      };
29    
30      VirtualMidiDevice::VirtualMidiDevice() {      VirtualMidiDevice::VirtualMidiDevice() : p(new private_data_t) {
         _private_data_t* p = new _private_data_t;  
         pPrivateData = p;  
31          atomic_t zero = ATOMIC_INIT(0);          atomic_t zero = ATOMIC_INIT(0);
32            atomic_t defaultVelocity = ATOMIC_INIT(127);
33          p->notesChanged = zero;          p->notesChanged = zero;
34          for (int i = 0; i < MIDI_KEYS; i++) {          for (int i = 0; i < MIDI_KEYS; i++) {
35              p->pNoteChanged[i]  = zero;              p->pNoteChanged[i]  = zero;
36              p->pNoteIsActive[i] = zero;              p->pNoteIsActive[i] = zero;
37                p->pNoteOnVelocity[i] = defaultVelocity;
38                p->pNoteOffVelocity[i] = defaultVelocity;
39          }          }
40      }      }
41    
42      VirtualMidiDevice::~VirtualMidiDevice() {      VirtualMidiDevice::~VirtualMidiDevice() {
43          if (pPrivateData) delete (_private_data_t*)pPrivateData;          delete p;
44      }      }
45    
46      bool VirtualMidiDevice::SendNoteOnToSampler(uint8_t Key, uint8_t Velocity) {      bool VirtualMidiDevice::SendNoteOnToSampler(uint8_t Key, uint8_t Velocity) {
47          if (Key >= MIDI_KEYS || Velocity > 127) return false;          if (Key >= MIDI_KEYS || Velocity > 127) return false;
         _private_data_t* p = (_private_data_t*)pPrivateData;  
48          event_t ev = { EVENT_TYPE_NOTEON, Key, Velocity };          event_t ev = { EVENT_TYPE_NOTEON, Key, Velocity };
49          if (p->events.write_space() <= 0) return false;          if (p->events.write_space() <= 0) return false;
50          p->events.push(&ev);          p->events.push(&ev);
# Line 51  namespace LinuxSampler { Line 53  namespace LinuxSampler {
53    
54      bool VirtualMidiDevice::SendNoteOffToSampler(uint8_t Key, uint8_t Velocity) {      bool VirtualMidiDevice::SendNoteOffToSampler(uint8_t Key, uint8_t Velocity) {
55          if (Key >= MIDI_KEYS || Velocity > 127) return false;          if (Key >= MIDI_KEYS || Velocity > 127) return false;
         _private_data_t* p = (_private_data_t*)pPrivateData;  
56          event_t ev = { EVENT_TYPE_NOTEOFF, Key, Velocity };          event_t ev = { EVENT_TYPE_NOTEOFF, Key, Velocity };
57          if (p->events.write_space() <= 0) return false;          if (p->events.write_space() <= 0) return false;
58          p->events.push(&ev);          p->events.push(&ev);
# Line 59  namespace LinuxSampler { Line 60  namespace LinuxSampler {
60      }      }
61    
62      bool VirtualMidiDevice::GetMidiEventFromDevice(event_t& Event) {      bool VirtualMidiDevice::GetMidiEventFromDevice(event_t& Event) {
         _private_data_t* p = (_private_data_t*)pPrivateData;  
63          return (p->events.pop(&Event) > 0);          return (p->events.pop(&Event) > 0);
64      }      }
65    
66      bool VirtualMidiDevice::NotesChanged() {      bool VirtualMidiDevice::NotesChanged() {
         _private_data_t* p = (_private_data_t*)pPrivateData;  
67          int c = atomic_read( &p->notesChanged );          int c = atomic_read( &p->notesChanged );
68          atomic_sub(c, &p->notesChanged );          atomic_sub(c, &p->notesChanged );
69          return c;          return c;
70      }      }
71    
72      bool VirtualMidiDevice::NoteChanged(uint8_t Key) {      bool VirtualMidiDevice::NoteChanged(uint8_t Key) {
         _private_data_t* p = (_private_data_t*)pPrivateData;  
73          int c = atomic_read( &(p->pNoteChanged)[Key] );          int c = atomic_read( &(p->pNoteChanged)[Key] );
74          atomic_sub(c, &(p->pNoteChanged)[Key] );          atomic_sub(c, &(p->pNoteChanged)[Key] );
75          return c;          return c;
76      }      }
77    
78      bool VirtualMidiDevice::NoteIsActive(uint8_t Key) {      bool VirtualMidiDevice::NoteIsActive(uint8_t Key) {
         _private_data_t* p = (_private_data_t*)pPrivateData;  
79          return atomic_read( &(p->pNoteIsActive)[Key] );          return atomic_read( &(p->pNoteIsActive)[Key] );
80      }      }
81    
82      void VirtualMidiDevice::SendNoteOnToDevice(uint8_t Key, uint8_t /*Velocity*/) {      uint8_t VirtualMidiDevice::NoteOnVelocity(uint8_t Key) {
83            return atomic_read( &(p->pNoteOnVelocity)[Key] );
84        }
85    
86        uint8_t VirtualMidiDevice::NoteOffVelocity(uint8_t Key) {
87            return atomic_read( &(p->pNoteOffVelocity)[Key] );
88        }
89    
90        void VirtualMidiDevice::SendNoteOnToDevice(uint8_t Key, uint8_t Velocity) {
91          if (Key >= MIDI_KEYS) return;          if (Key >= MIDI_KEYS) return;
92          _private_data_t* p = (_private_data_t*)pPrivateData;          atomic_set( &(p->pNoteOnVelocity)[Key], Velocity );
93          atomic_inc( &(p->pNoteIsActive)[Key] );          atomic_inc( &(p->pNoteIsActive)[Key] );
94          atomic_inc( &(p->pNoteChanged)[Key] );          atomic_inc( &(p->pNoteChanged)[Key] );
95          atomic_inc( &p->notesChanged );          atomic_inc( &p->notesChanged );
96      }      }
97    
98      void VirtualMidiDevice::SendNoteOffToDevice(uint8_t Key, uint8_t /*Velocity*/) {      void VirtualMidiDevice::SendNoteOffToDevice(uint8_t Key, uint8_t Velocity) {
99          if (Key >= MIDI_KEYS) return;          if (Key >= MIDI_KEYS) return;
100          _private_data_t* p = (_private_data_t*)pPrivateData;          atomic_set( &(p->pNoteOffVelocity)[Key], Velocity );
101          atomic_dec( &(p->pNoteIsActive)[Key] );          atomic_dec( &(p->pNoteIsActive)[Key] );
102          atomic_inc( &(p->pNoteChanged)[Key] );          atomic_inc( &(p->pNoteChanged)[Key] );
103          atomic_inc( &p->notesChanged );          atomic_inc( &p->notesChanged );

Legend:
Removed from v.1659  
changed lines
  Added in v.1896

  ViewVC Help
Powered by ViewVC