/[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 2025 by schoenebeck, Sun Nov 1 18:47:59 2009 UTC revision 2385 by schoenebeck, Fri Dec 14 17:41:32 2012 UTC
# Line 1  Line 1 
1  /*  /*
2      Copyright (C) 2008 - 2009 Christian Schoenebeck      Copyright (C) 2008 - 2012 Christian Schoenebeck
3   */   */
4    
5  #include "VirtualMidiDevice.h"  #include "VirtualMidiDevice.h"
# Line 50  namespace LinuxSampler { Line 50  namespace LinuxSampler {
50      VirtualMidiDevice::~VirtualMidiDevice() {      VirtualMidiDevice::~VirtualMidiDevice() {
51          delete p;          delete p;
52      }      }
53        
54        void VirtualMidiDevice::SetMaxEvents(int n) {
55            p->events.resize(n);
56        }
57    
58      bool VirtualMidiDevice::SendNoteOnToSampler(uint8_t Key, uint8_t Velocity) {      bool VirtualMidiDevice::SendNoteOnToSampler(uint8_t Key, uint8_t Velocity) {
59          if (Key >= MIDI_KEYS || Velocity > 127) return false;          if (Key >= MIDI_KEYS || Velocity > 127) return false;
60            if (Velocity == 0) {
61                return SendNoteOffToSampler(Key, Velocity);
62            }
63          event_t ev = { EVENT_TYPE_NOTEON, Key, Velocity };          event_t ev = { EVENT_TYPE_NOTEON, Key, Velocity };
64          if (p->events.write_space() <= 0) return false;          if (p->events.write_space() <= 0) return false;
65          p->events.push(&ev);          p->events.push(&ev);
# Line 121  namespace LinuxSampler { Line 128  namespace LinuxSampler {
128    
129      void VirtualMidiDevice::SendNoteOnToDevice(uint8_t Key, uint8_t Velocity) {      void VirtualMidiDevice::SendNoteOnToDevice(uint8_t Key, uint8_t Velocity) {
130          if (Key >= MIDI_KEYS) return;          if (Key >= MIDI_KEYS) return;
131            if (Velocity == 0) {
132                SendNoteOffToDevice(Key, Velocity);
133                return;
134            }
135          atomic_set( &(p->pNoteOnVelocity)[Key], Velocity );          atomic_set( &(p->pNoteOnVelocity)[Key], Velocity );
136          atomic_inc( &(p->pNoteIsActive)[Key] );          atomic_inc( &(p->pNoteIsActive)[Key] );
137          atomic_inc( &(p->pNoteChanged)[Key] );          atomic_inc( &(p->pNoteChanged)[Key] );
# Line 130  namespace LinuxSampler { Line 141  namespace LinuxSampler {
141      void VirtualMidiDevice::SendNoteOffToDevice(uint8_t Key, uint8_t Velocity) {      void VirtualMidiDevice::SendNoteOffToDevice(uint8_t Key, uint8_t Velocity) {
142          if (Key >= MIDI_KEYS) return;          if (Key >= MIDI_KEYS) return;
143          atomic_set( &(p->pNoteOffVelocity)[Key], Velocity );          atomic_set( &(p->pNoteOffVelocity)[Key], Velocity );
144          atomic_dec( &(p->pNoteIsActive)[Key] );          if (atomic_read( &(p->pNoteIsActive)[Key] )) // only decrement if not zero
145                atomic_dec( &(p->pNoteIsActive)[Key] );
146          atomic_inc( &(p->pNoteChanged)[Key] );          atomic_inc( &(p->pNoteChanged)[Key] );
147          atomic_inc( &p->notesChanged );          atomic_inc( &p->notesChanged );
148      }      }

Legend:
Removed from v.2025  
changed lines
  Added in v.2385

  ViewVC Help
Powered by ViewVC