linuxsampler 2.3.1
LinuxSampler::VirtualMidiDevice Class Reference

Light-weight MIDI interface (for MIDI in & out) intended to be used by pure software MIDI "devices", that is e.g. More...

#include <VirtualMidiDevice.h>

Inheritance diagram for LinuxSampler::VirtualMidiDevice:
LinuxSampler::InstrumentEditor

Classes

struct  event_t
 

Public Types

enum  event_type_t {
  EVENT_TYPE_NOTEON = 1 , EVENT_TYPE_NOTEOFF = 2 , EVENT_TYPE_CC = 3 , EVENT_TYPE_PITCHBEND ,
  EVENT_TYPE_PROGRAM , EVENT_TYPE_CHPRESSURE
}
 

Public Member Functions

bool SendNoteOnToSampler (uint8_t Key, uint8_t Velocity)
 Sends a MIDI note on event to the sampler.
 
bool SendNoteOffToSampler (uint8_t Key, uint8_t Velocity)
 Sends a MIDI note off event to the sampler.
 
bool SendCCToSampler (uint8_t Controller, uint8_t Value)
 Sends a MIDI Control Change event to the sampler.
 
bool SendChannelPressureToSampler (uint8_t Pressure)
 Sends a MIDI Channel Pressure (aftertouch) event to the sampler.
 
bool SendPitchBendToSampler (int Pitch)
 Sends a MIDI Pitch Bend event to the sampler.
 
bool SendProgramChangeToSampler (uint8_t Program)
 Sends a MIDI Program Change event to the sampler.
 
bool NotesChanged ()
 Can be called by the virtual MIDI device to check whether a new note on or note off MIDI event arrived to the sampler during the last call to this method.
 
bool NoteChanged (uint8_t Key)
 Can be called by the virtual MIDI device to check whether a new note on or note off MIDI event arrived to the sampler for Key during the last call to this method.
 
bool NoteIsActive (uint8_t Key)
 Can be called by the virtual MIDI device to check which key / note is currently active by the sampler, e.g.
 
uint8_t NoteOnVelocity (uint8_t Key)
 Returns the velocity of the last note on event.
 
uint8_t NoteOffVelocity (uint8_t Key)
 Returns the velocity of the last note off event.
 
bool ControllersChanged ()
 Can be called by the virtual MIDI device to check whether a Control Change MIDI event arrived to the sampler during the last call to this method.
 
bool ControllerChanged (uint8_t Controller)
 Can be called by the virtual MIDI device to check whether a Control Change MIDI event arrived to the sampler for Controller during the last call to this method.
 
uint8_t ControllerValue (uint8_t Controller)
 Returns the value of the last Control Change event.
 
void SendNoteOnToDevice (uint8_t Key, uint8_t Velocity)
 Informs the virtual MIDI device that a note on event occured (e.g.
 
void SendNoteOffToDevice (uint8_t Key, uint8_t Velocity)
 Informs the virtual MIDI device that a note off event occured (e.g.
 
void SendCCToDevice (uint8_t Controller, uint8_t Value)
 Informs the virtual MIDI device that a Control Change event occured (e.g.
 
bool GetMidiEventFromDevice (event_t &Event)
 Gets the next pending MIDI event from the virtual MIDI device by using a lockfree FIFO.
 
void SetMaxEvents (int n)
 Adjusts the internal event buffer to cover at least the given amount of MIDI events.
 
void Reset ()
 Intended to be called on "panic" / all notes off situations.
 
 VirtualMidiDevice ()
 Constructor.
 
virtual ~VirtualMidiDevice ()
 Destructor.
 

Detailed Description

Light-weight MIDI interface (for MIDI in & out) intended to be used by pure software MIDI "devices", that is e.g.

a graphical virtual MIDI keyboard in an instrument editor or in a sampler frontend. This class should not be used for regular MIDI input device drivers for the sampler. This primitive interface by design doesn't care about jitter, fast event delivery or masses and masses of events in a short time!

Definition at line 20 of file VirtualMidiDevice.h.

Member Enumeration Documentation

◆ event_type_t

Enumerator
EVENT_TYPE_NOTEON 
EVENT_TYPE_NOTEOFF 
EVENT_TYPE_CC 
EVENT_TYPE_PITCHBEND 
EVENT_TYPE_PROGRAM 
EVENT_TYPE_CHPRESSURE 

Definition at line 22 of file VirtualMidiDevice.h.

Constructor & Destructor Documentation

◆ VirtualMidiDevice()

LinuxSampler::VirtualMidiDevice::VirtualMidiDevice ( )

Constructor.

◆ ~VirtualMidiDevice()

virtual LinuxSampler::VirtualMidiDevice::~VirtualMidiDevice ( )
virtual

Destructor.

Member Function Documentation

◆ ControllerChanged()

bool LinuxSampler::VirtualMidiDevice::ControllerChanged ( uint8_t  Controller)

Can be called by the virtual MIDI device to check whether a Control Change MIDI event arrived to the sampler for Controller during the last call to this method.

So this is a asynchronously, "polling" based communication mechanism, which works in conjunction with the ControllerValue() method call.

◆ ControllersChanged()

bool LinuxSampler::VirtualMidiDevice::ControllersChanged ( )

Can be called by the virtual MIDI device to check whether a Control Change MIDI event arrived to the sampler during the last call to this method.

So this is a asynchronously, "polling" based communication mechanism, which works in conjunction with the ControllerValue() method call.

◆ ControllerValue()

uint8_t LinuxSampler::VirtualMidiDevice::ControllerValue ( uint8_t  Controller)

Returns the value of the last Control Change event.

No FIFO is used!

◆ GetMidiEventFromDevice()

bool LinuxSampler::VirtualMidiDevice::GetMidiEventFromDevice ( event_t Event)

Gets the next pending MIDI event from the virtual MIDI device by using a lockfree FIFO.

Note: this method is usually only called by the sampler.

Parameters
Event- destination for writing the next event to
Returns
true on success, false if no event pending

◆ NoteChanged()

bool LinuxSampler::VirtualMidiDevice::NoteChanged ( uint8_t  Key)

Can be called by the virtual MIDI device to check whether a new note on or note off MIDI event arrived to the sampler for Key during the last call to this method.

So this is a asynchronously, "polling" based communication mechanism, which works in conjunction with the NoteIsActive() method call.

◆ NoteIsActive()

bool LinuxSampler::VirtualMidiDevice::NoteIsActive ( uint8_t  Key)

Can be called by the virtual MIDI device to check which key / note is currently active by the sampler, e.g.

to highlight the respective keys on a graphical virtual keyboard.

See also
NotesChanged(), NoteChanged()

◆ NoteOffVelocity()

uint8_t LinuxSampler::VirtualMidiDevice::NoteOffVelocity ( uint8_t  Key)

Returns the velocity of the last note off event.

No FIFO is used!

◆ NoteOnVelocity()

uint8_t LinuxSampler::VirtualMidiDevice::NoteOnVelocity ( uint8_t  Key)

Returns the velocity of the last note on event.

No FIFO is used!

◆ NotesChanged()

bool LinuxSampler::VirtualMidiDevice::NotesChanged ( )

Can be called by the virtual MIDI device to check whether a new note on or note off MIDI event arrived to the sampler during the last call to this method.

So this is a asynchronously, "polling" based communication mechanism, which works in conjunction with the NoteIsActive() method call.

◆ Reset()

void LinuxSampler::VirtualMidiDevice::Reset ( )

Intended to be called on "panic" / all notes off situations.

Calling this method will reset all internal atomic flags, such that the state reflects that no note is currently active (its key pressed down).

Only exception: this method currently does not reset the internal ring buffer which is used to transmit MIDI events to the sampler.

Also note that this method is not fully concurrency safe. That means since only flags are reset, calling this method means no harm, but it might conflict with MIDI events etc and thus still cause hanging notes durcing such a specific concurrency conflict. Or in other words: the user might need to trigger the "panic" button multiple times.

◆ SendCCToDevice()

void LinuxSampler::VirtualMidiDevice::SendCCToDevice ( uint8_t  Controller,
uint8_t  Value 
)

Informs the virtual MIDI device that a Control Change event occured (e.g.

caused by a MIDI keyboard connected to the sampler). Communication acts asynchronously, that is this method call doesn't lock in any way and returns immediately. It is thus realtime safe.

Note: this method is usually only called by the sampler.

See also
ControllersChanged(), ControllerValue()

◆ SendCCToSampler()

bool LinuxSampler::VirtualMidiDevice::SendCCToSampler ( uint8_t  Controller,
uint8_t  Value 
)

Sends a MIDI Control Change event to the sampler.

Returns
true on success, false if internal FIFO full (or provided values invalid)

◆ SendChannelPressureToSampler()

bool LinuxSampler::VirtualMidiDevice::SendChannelPressureToSampler ( uint8_t  Pressure)

Sends a MIDI Channel Pressure (aftertouch) event to the sampler.

Returns
true on success, false if internal FIFO full (or provided value invalid)

◆ SendNoteOffToDevice()

void LinuxSampler::VirtualMidiDevice::SendNoteOffToDevice ( uint8_t  Key,
uint8_t  Velocity 
)

Informs the virtual MIDI device that a note off event occured (e.g.

caused by a MIDI keyboard connected to the sampler). Communication acts asynchronously, that is this method call doesn't lock in any way and returns immediately. It is thus realtime safe.

Note: this method is usually only called by the sampler.

See also
ActiveNotesChanged(), NoteIsActive()

◆ SendNoteOffToSampler()

bool LinuxSampler::VirtualMidiDevice::SendNoteOffToSampler ( uint8_t  Key,
uint8_t  Velocity 
)

Sends a MIDI note off event to the sampler.

Returns
true on success, false if internal FIFO full (or provided values invalid)

◆ SendNoteOnToDevice()

void LinuxSampler::VirtualMidiDevice::SendNoteOnToDevice ( uint8_t  Key,
uint8_t  Velocity 
)

Informs the virtual MIDI device that a note on event occured (e.g.

caused by a MIDI keyboard connected to the sampler). Communication acts asynchronously, that is this method call doesn't lock in any way and returns immediately. It is thus realtime safe.

Note: this method is usually only called by the sampler.

See also
ActiveNotesChanged(), NoteIsActive()

◆ SendNoteOnToSampler()

bool LinuxSampler::VirtualMidiDevice::SendNoteOnToSampler ( uint8_t  Key,
uint8_t  Velocity 
)

Sends a MIDI note on event to the sampler.

Returns
true on success, false if internal FIFO full (or provided values invalid)

◆ SendPitchBendToSampler()

bool LinuxSampler::VirtualMidiDevice::SendPitchBendToSampler ( int  Pitch)

Sends a MIDI Pitch Bend event to the sampler.

Parameters
Pitch- MIDI pitch value (-8192 ... +8191)
Returns
true on success, false if internal FIFO full (or provided pitch value out of valid range)

◆ SendProgramChangeToSampler()

bool LinuxSampler::VirtualMidiDevice::SendProgramChangeToSampler ( uint8_t  Program)

Sends a MIDI Program Change event to the sampler.

If you want to change the sound bank, call SendCCToSampler() (with controller = 0 for bank select MSB and/or controller = 32 for bank select LSB) before calling this method.

Parameters
Program- MIDI program number
Returns
true on success, false if internal FIFO full (or provided value invalid)

◆ SetMaxEvents()

void LinuxSampler::VirtualMidiDevice::SetMaxEvents ( int  n)

Adjusts the internal event buffer to cover at least the given amount of MIDI events.

This might be useful, since the internal event buffer is by default quite small (i.e. just 12 events).

This method is not thread safe! Any operations upon this device have to be stopped before calling this method!


The documentation for this class was generated from the following file: