/[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 2384 by schoenebeck, Fri Dec 14 16:04:49 2012 UTC revision 2521 by schoenebeck, Wed Feb 19 19:02:43 2014 UTC
# Line 1  Line 1 
1  /*  /*
2      Copyright (C) 2008 - 2012 Christian Schoenebeck      Copyright (C) 2008 - 2014 Christian Schoenebeck
3   */   */
4    
5  #include "VirtualMidiDevice.h"  #include "VirtualMidiDevice.h"
# Line 57  namespace LinuxSampler { Line 57  namespace LinuxSampler {
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 79  namespace LinuxSampler { Line 82  namespace LinuxSampler {
82          return true;          return true;
83      }      }
84    
85        bool VirtualMidiDevice::SendPitchBendToSampler(int Pitch) {
86            if (Pitch < -8192 || Pitch > 8191) return false;
87            Pitch += 8192;
88            // order: LSB, MSB like it would be in a regular pitch bend MIDI message
89            event_t ev = { EVENT_TYPE_PITCHBEND, Pitch & 0x7f, (Pitch >> 7) & 0x7f };
90            if (p->events.write_space() <= 0) return false;
91            p->events.push(&ev);
92            return true;
93        }
94    
95        bool VirtualMidiDevice::SendProgramChangeToSampler(int Program) {
96            if (Program < 0 || Program > 127) return false;
97            event_t ev = { EVENT_TYPE_PROGRAM, Program, 0 };
98            if (p->events.write_space() <= 0) return false;
99            p->events.push(&ev);
100            return true;
101        }
102    
103      bool VirtualMidiDevice::GetMidiEventFromDevice(event_t& Event) {      bool VirtualMidiDevice::GetMidiEventFromDevice(event_t& Event) {
104          return (p->events.pop(&Event) > 0);          return (p->events.pop(&Event) > 0);
105      }      }
# Line 125  namespace LinuxSampler { Line 146  namespace LinuxSampler {
146    
147      void VirtualMidiDevice::SendNoteOnToDevice(uint8_t Key, uint8_t Velocity) {      void VirtualMidiDevice::SendNoteOnToDevice(uint8_t Key, uint8_t Velocity) {
148          if (Key >= MIDI_KEYS) return;          if (Key >= MIDI_KEYS) return;
149            if (Velocity == 0) {
150                SendNoteOffToDevice(Key, Velocity);
151                return;
152            }
153          atomic_set( &(p->pNoteOnVelocity)[Key], Velocity );          atomic_set( &(p->pNoteOnVelocity)[Key], Velocity );
154          atomic_inc( &(p->pNoteIsActive)[Key] );          atomic_inc( &(p->pNoteIsActive)[Key] );
155          atomic_inc( &(p->pNoteChanged)[Key] );          atomic_inc( &(p->pNoteChanged)[Key] );

Legend:
Removed from v.2384  
changed lines
  Added in v.2521

  ViewVC Help
Powered by ViewVC