diff options
author | David Robillard <d@drobilla.net> | 2016-11-07 05:14:55 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2016-12-03 15:28:19 -0500 |
commit | 398a318934769dae51efe972f7ffdefc52ea2963 (patch) | |
tree | 5b68a8fac44f0c154e7e00fd45d9e7f2c16e35fb /libs/evoral/src | |
parent | bfbc4566ad82573a57e1ec84d583f308ee35eef0 (diff) |
Fix event type and parameter type confusion
I'm not sure if this is really the best way to do event types (should it
just be a completely static enum in evoral, or completely dynamic and
provided by the type map, or a mix like currently?), but previously the
event type was frequently set to either total garbage, or parameter
types, which are a different thing.
This fixes all those cases, and makes Evoral::EventType an enum so the
compiler will warn about implicit conversions from int.
Diffstat (limited to 'libs/evoral/src')
-rw-r--r-- | libs/evoral/src/Note.cpp | 5 | ||||
-rw-r--r-- | libs/evoral/src/Sequence.cpp | 33 |
2 files changed, 20 insertions, 18 deletions
diff --git a/libs/evoral/src/Note.cpp b/libs/evoral/src/Note.cpp index 3b56a33241..52a4d6335b 100644 --- a/libs/evoral/src/Note.cpp +++ b/libs/evoral/src/Note.cpp @@ -30,9 +30,8 @@ namespace Evoral { template<typename Time> Note<Time>::Note(uint8_t chan, Time t, Time l, uint8_t n, uint8_t v) - // FIXME: types? - : _on_event (0xDE, t, 3, NULL, true) - , _off_event (0xAD, t + l, 3, NULL, true) + : _on_event (MIDI_EVENT, t, 3, NULL, true) + , _off_event (MIDI_EVENT, t + l, 3, NULL, true) { assert(chan < 16); diff --git a/libs/evoral/src/Sequence.cpp b/libs/evoral/src/Sequence.cpp index 3098d0339d..14e3b65f37 100644 --- a/libs/evoral/src/Sequence.cpp +++ b/libs/evoral/src/Sequence.cpp @@ -63,7 +63,7 @@ template<typename Time> Sequence<Time>::const_iterator::const_iterator() : _seq(NULL) , _event(boost::shared_ptr< Event<Time> >(new Event<Time>())) - , _active_patch_change_message (0) + , _active_patch_change_message (NO_EVENT) , _type(NIL) , _is_end(true) , _control_iter(_control_iters.end()) @@ -191,7 +191,7 @@ Sequence<Time>::const_iterator::const_iterator(const Sequence<Time>& // Allocate a new event for storing the current event in MIDI format _event = boost::shared_ptr< Event<Time> >( - new Event<Time>(0, Time(), 4, NULL, true)); + new Event<Time>(NO_EVENT, Time(), 4, NULL, true)); // Set event from chosen sub-iterator set_event(); @@ -515,9 +515,8 @@ Sequence<Time>::Sequence(const Sequence<Time>& other) assert(! _end_iter._lock); } -/** Write the controller event pointed to by \a iter to \a ev. - * The buffer of \a ev will be allocated or resized as necessary. - * The event_type of \a ev should be set to the expected output type. +/** Write the controller event pointed to by `iter` to `ev`. + * The buffer of `ev` will be allocated or resized as necessary. * \return true on success */ template<typename Time> @@ -527,15 +526,14 @@ Sequence<Time>::control_to_midi_event( const ControlIterator& iter) const { assert(iter.list.get()); - const uint32_t event_type = iter.list->parameter().type(); // initialize the event pointer with a new event, if necessary if (!ev) { - ev = boost::shared_ptr< Event<Time> >(new Event<Time>(event_type, Time(), 3, NULL, true)); + ev = boost::shared_ptr< Event<Time> >(new Event<Time>(NO_EVENT, Time(), 3, NULL, true)); } - uint8_t midi_type = _type_map.parameter_midi_type(iter.list->parameter()); - ev->set_event_type(_type_map.midi_event_type(midi_type)); + const uint8_t midi_type = _type_map.parameter_midi_type(iter.list->parameter()); + ev->set_event_type(MIDI_EVENT); ev->set_id(-1); switch (midi_type) { case MIDI_CMD_CONTROL: @@ -933,23 +931,28 @@ Sequence<Time>::append(const Event<Time>& ev, event_id_t evid) _bank[ev.channel()] |= ev.cc_value(); } } else if (ev.is_cc()) { + const ParameterType ptype = _type_map.midi_parameter_type(ev.buffer(), ev.size()); append_control_unlocked( - Parameter(ev.event_type(), ev.channel(), ev.cc_number()), + Parameter(ptype, ev.channel(), ev.cc_number()), ev.time(), ev.cc_value(), evid); } else if (ev.is_pgm_change()) { /* write a patch change with this program change and any previously set-up bank number */ - append_patch_change_unlocked (PatchChange<Time> (ev.time(), ev.channel(), ev.pgm_number(), _bank[ev.channel()]), evid); + append_patch_change_unlocked ( + PatchChange<Time> (ev.time(), ev.channel(), + ev.pgm_number(), _bank[ev.channel()]), evid); } else if (ev.is_pitch_bender()) { + const ParameterType ptype = _type_map.midi_parameter_type(ev.buffer(), ev.size()); append_control_unlocked( - Parameter(ev.event_type(), ev.channel()), + Parameter(ptype, ev.channel()), ev.time(), double ((0x7F & ev.pitch_bender_msb()) << 7 | (0x7F & ev.pitch_bender_lsb())), evid); } else if (ev.is_poly_pressure()) { append_control_unlocked (Parameter (ev.event_type(), ev.channel(), ev.poly_note()), ev.time(), ev.poly_pressure(), evid); } else if (ev.is_channel_pressure()) { + const ParameterType ptype = _type_map.midi_parameter_type(ev.buffer(), ev.size()); append_control_unlocked( - Parameter(ev.event_type(), ev.channel()), + Parameter(ptype, ev.channel()), ev.time(), ev.channel_pressure(), evid); } else if (!_type_map.type_is_midi(ev.event_type())) { printf("WARNING: Sequence: Unknown event type %X: ", ev.event_type()); @@ -1215,7 +1218,7 @@ template<typename Time> typename Sequence<Time>::SysExes::const_iterator Sequence<Time>::sysex_lower_bound (Time t) const { - SysExPtr search (new Event<Time> (0, t)); + SysExPtr search (new Event<Time> (NO_EVENT, t)); typename Sequence<Time>::SysExes::const_iterator i = _sysexes.lower_bound (search); assert (i == _sysexes.end() || (*i)->time() >= t); return i; @@ -1250,7 +1253,7 @@ template<typename Time> typename Sequence<Time>::SysExes::iterator Sequence<Time>::sysex_lower_bound (Time t) { - SysExPtr search (new Event<Time> (0, t)); + SysExPtr search (new Event<Time> (NO_EVENT, t)); typename Sequence<Time>::SysExes::iterator i = _sysexes.lower_bound (search); assert (i == _sysexes.end() || (*i)->time() >= t); return i; |