--- linuxsampler/trunk/src/drivers/midi/VirtualMidiDevice.cpp 2014/02/19 19:02:43 2521 +++ linuxsampler/trunk/src/drivers/midi/VirtualMidiDevice.cpp 2021/08/04 18:04:12 3986 @@ -1,5 +1,5 @@ /* - Copyright (C) 2008 - 2014 Christian Schoenebeck + Copyright (C) 2008 - 2021 Christian Schoenebeck */ #include "VirtualMidiDevice.h" @@ -15,6 +15,9 @@ // by mouse (and the user not being Billy the Kid) #define MAX_EVENTS 12 +#define DEFAULT_CC_VALUE 0 +#define DEFAULT_VELOCITY 127 + namespace LinuxSampler { struct VirtualMidiDevice::private_data_t { @@ -29,6 +32,30 @@ RingBuffer events; private_data_t() : events(MAX_EVENTS, 0) {} + + void resetNotes() { + for (int i = 0; i < MIDI_KEYS; i++) { + atomic_set( &pNoteOnVelocity[i], DEFAULT_VELOCITY ); + atomic_set( &pNoteOffVelocity[i], DEFAULT_VELOCITY ); + atomic_set( &pNoteIsActive[i], 0 ); + // should be non zero, because we changed the state above, that + // way forcing the virtual MIDI device user (e.g. UI) to refresh + atomic_inc( &pNoteChanged[i] ); + } + // this should also be non zero, for the same reason as above + atomic_inc( ¬esChanged ); + } + + void resetCCs() { + for (int i = 0; i < MIDI_CONTROLLERS; i++) { + atomic_set( &pCCValue[i], DEFAULT_CC_VALUE ); + // should be non zero, because we changed the state above, that + // way forcing the virtual MIDI device user (e.g. UI) to refresh + atomic_inc( &pCCChanged[i] ); + } + // this should also be non zero, for the same reason as above + atomic_inc( &ccsChanged ); + } }; VirtualMidiDevice::VirtualMidiDevice() : p(new private_data_t) { @@ -82,18 +109,30 @@ return true; } + bool VirtualMidiDevice::SendChannelPressureToSampler(uint8_t Pressure) { + if (Pressure > 127) return false; + event_t ev = { EVENT_TYPE_CHPRESSURE, 128 /*actually ignored by engine*/, Pressure }; + if (p->events.write_space() <= 0) return false; + p->events.push(&ev); + return true; + } + bool VirtualMidiDevice::SendPitchBendToSampler(int Pitch) { if (Pitch < -8192 || Pitch > 8191) return false; Pitch += 8192; // order: LSB, MSB like it would be in a regular pitch bend MIDI message - event_t ev = { EVENT_TYPE_PITCHBEND, Pitch & 0x7f, (Pitch >> 7) & 0x7f }; + event_t ev = { + EVENT_TYPE_PITCHBEND, + static_cast(Pitch & 0x7f), + static_cast((Pitch >> 7) & 0x7f) + }; if (p->events.write_space() <= 0) return false; p->events.push(&ev); return true; } - bool VirtualMidiDevice::SendProgramChangeToSampler(int Program) { - if (Program < 0 || Program > 127) return false; + bool VirtualMidiDevice::SendProgramChangeToSampler(uint8_t Program) { + if (Program > 127) return false; event_t ev = { EVENT_TYPE_PROGRAM, Program, 0 }; if (p->events.write_space() <= 0) return false; p->events.push(&ev); @@ -172,4 +211,9 @@ atomic_inc( &p->ccsChanged ); } + void VirtualMidiDevice::Reset() { + p->resetNotes(); + p->resetCCs(); + } + } // namespace LinuxSampler