Update API to send immediate events

This is to allow passing the EventType to the Buffer, using a
consistent {[Time], Type, size, data} API, that is equivalent
for all classes.

This is particularly useful for Lua scripts and plugin UIs
than can call `write_immediate_event()` while being ignorant
where the data is routed to (MIDI tracks, plugins, processors).
This commit is contained in:
Robin Gareus 2020-09-20 00:18:41 +02:00
parent 7c37a18b75
commit 2f68656679
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
6 changed files with 14 additions and 14 deletions

View File

@ -73,7 +73,7 @@ public:
int set_state (const XMLNode&, int version);
void midi_panic(void);
bool write_immediate_event(size_t size, const uint8_t* buf);
bool write_immediate_event (Evoral::EventType event_type, size_t size, const uint8_t* buf);
/** A control that will send "immediate" events to a MIDI track when twiddled */
struct MidiControl : public AutomationControl {

View File

@ -173,7 +173,7 @@ public:
pframes_t nframes, samplecnt_t offset);
bool write_immediate_event (size_t size, const uint8_t* buf);
bool write_immediate_event (Evoral::EventType event_type, size_t size, const uint8_t* buf);
void realtime_handle_transport_stopped ();
void realtime_locate (bool);

View File

@ -84,7 +84,7 @@ public:
bool reset_parameters_to_default ();
bool can_reset_all_parameters ();
bool write_immediate_event (size_t size, const uint8_t* buf);
bool write_immediate_event (Evoral::EventType event_type, size_t size, const uint8_t* buf);
void automation_run (samplepos_t, pframes_t, bool only_active = false);
bool find_next_event (double, double, Evoral::ControlEvent&, bool only_active = true) const;

View File

@ -589,24 +589,24 @@ MidiTrack::midi_panic()
DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 delivers panic data\n", name()));
for (uint8_t channel = 0; channel <= 0xF; channel++) {
uint8_t ev[3] = { ((uint8_t) (MIDI_CMD_CONTROL | channel)), ((uint8_t) MIDI_CTL_SUSTAIN), 0 };
write_immediate_event(3, ev);
write_immediate_event (Evoral::MIDI_EVENT, 3, ev);
ev[1] = MIDI_CTL_ALL_NOTES_OFF;
write_immediate_event(3, ev);
write_immediate_event (Evoral::MIDI_EVENT, 3, ev);
ev[1] = MIDI_CTL_RESET_CONTROLLERS;
write_immediate_event(3, ev);
write_immediate_event (Evoral::MIDI_EVENT, 3, ev);
}
}
/** \return true on success, false on failure (no buffer space left)
*/
bool
MidiTrack::write_immediate_event(size_t size, const uint8_t* buf)
MidiTrack::write_immediate_event(Evoral::EventType event_type, size_t size, const uint8_t* buf)
{
if (!Evoral::midi_event_is_valid(buf, size)) {
cerr << "WARNING: Ignoring illegal immediate MIDI event" << endl;
return false;
}
return (_immediate_events.write (0, Evoral::MIDI_EVENT, size, buf) == size);
return (_immediate_events.write (0, event_type, size, buf) == size);
}
void
@ -696,7 +696,7 @@ MidiTrack::MidiControl::actually_set_value (double val, PBD::Controllable::Group
size = 0;
assert(false);
}
_route->write_immediate_event(size, ev);
_route->write_immediate_event(Evoral::MIDI_EVENT, size, ev);
}
AutomationControl::actually_set_value(val, group_override);
@ -834,7 +834,7 @@ MidiTrack::act_on_mute ()
DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 delivers mute message to channel %2\n", name(), channel+1));
uint8_t ev[3] = { ((uint8_t) (MIDI_CMD_CONTROL | channel)), MIDI_CTL_SUSTAIN, 0 };
write_immediate_event (3, ev);
write_immediate_event (Evoral::MIDI_EVENT, 3, ev);
/* Note we do not send MIDI_CTL_ALL_NOTES_OFF here, since this may
silence notes that came from another non-muted track. */

View File

@ -386,12 +386,12 @@ Plugin::preset_by_uri (const string& uri)
}
bool
Plugin::write_immediate_event (size_t size, const uint8_t* buf)
Plugin::write_immediate_event (Evoral::EventType event_type, size_t size, const uint8_t* buf)
{
if (!Evoral::midi_event_is_valid (buf, size)) {
return false;
}
return (_immediate_events.write (0, Evoral::MIDI_EVENT, size, buf) == size);
return (_immediate_events.write (0, event_type, size, buf) == size);
}
int

View File

@ -789,11 +789,11 @@ PluginInsert::bypassable_changed ()
}
bool
PluginInsert::write_immediate_event (size_t size, const uint8_t* buf)
PluginInsert::write_immediate_event (Evoral::EventType event_type, size_t size, const uint8_t* buf)
{
bool rv = true;
for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
if (!(*i)->write_immediate_event (size, buf)) {
if (!(*i)->write_immediate_event (event_type, size, buf)) {
rv = false;
}
}