- write_lock();
- _edited = true;
-
- const MIDIEvent& ev = (const MIDIEvent&)event;
-
- assert(_notes.empty() || ev.time() >= _notes.back()->time());
- assert(_writing);
-
- if (ev.is_note_on()) {
- append_note_on_unlocked(ev.channel(), ev.time(), ev.note(),
- ev.velocity());
- } else if (ev.is_note_off()) {
- append_note_off_unlocked(ev.channel(), ev.time(), ev.note());
- } else if (!_type_map.type_is_midi(ev.event_type())) {
- printf("WARNING: Sequence: Unknown event type %X\n", ev.event_type());
- } else if (ev.is_cc()) {
- append_control_unlocked(
- Evoral::MIDI::ContinuousController(ev.event_type(), ev.channel(), ev.cc_number()),
- ev.time(), ev.cc_value());
- } else if (ev.is_pgm_change()) {
- append_control_unlocked(
- Evoral::MIDI::ProgramChange(ev.event_type(), ev.channel()),
- ev.time(), ev.pgm_number());
- } else if (ev.is_pitch_bender()) {
- append_control_unlocked(
- Evoral::MIDI::PitchBender(ev.event_type(), ev.channel()),
- ev.time(), double( (0x7F & ev.pitch_bender_msb()) << 7
- | (0x7F & ev.pitch_bender_lsb()) ));
- } else if (ev.is_channel_pressure()) {
- append_control_unlocked(
- Evoral::MIDI::ChannelPressure(ev.event_type(), ev.channel()),
- ev.time(), ev.channel_pressure());
- } else {
- printf("WARNING: Sequence: Unknown MIDI event type %X\n", ev.type());
- }
+ WriteLock lock(write_lock());
+
+ const MIDIEvent<Time>& ev = (const MIDIEvent<Time>&)event;
+
+ assert(_notes.empty() || ev.time() >= (*_notes.rbegin())->time());
+ assert(_writing);
+
+ if (!midi_event_is_valid(ev.buffer(), ev.size())) {
+ cerr << "WARNING: Sequence ignoring illegal MIDI event" << endl;
+ return;
+ }
+
+ if (ev.is_note_on()) {
+ NotePtr note(new Note<Time>(ev.channel(), ev.time(), 0, ev.note(), ev.velocity()));
+ append_note_on_unlocked (note, evid);
+ } else if (ev.is_note_off()) {
+ NotePtr note(new Note<Time>(ev.channel(), ev.time(), 0, ev.note(), ev.velocity()));
+ /* XXX note: event ID is discarded because we merge the on+off events into
+ a single note object
+ */
+ append_note_off_unlocked (note);
+ } else if (ev.is_sysex()) {
+ append_sysex_unlocked(ev, evid);
+ } else if (ev.is_cc() && (ev.cc_number() == MIDI_CTL_MSB_BANK || ev.cc_number() == MIDI_CTL_LSB_BANK)) {
+ /* note bank numbers in our _bank[] array, so that we can write an event when the program change arrives */
+ if (ev.cc_number() == MIDI_CTL_MSB_BANK) {
+ _bank[ev.channel()] &= (0x7f << 7);
+ _bank[ev.channel()] |= ev.cc_value() << 7;
+ } else {
+ _bank[ev.channel()] &= 0x7f;
+ _bank[ev.channel()] |= ev.cc_value();
+ }
+ } else if (ev.is_cc()) {
+ append_control_unlocked(
+ Evoral::MIDI::ContinuousController(ev.event_type(), 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);
+ } else if (ev.is_pitch_bender()) {
+ append_control_unlocked(
+ Evoral::MIDI::PitchBender(ev.event_type(), ev.channel()),
+ ev.time(), double ((0x7F & ev.pitch_bender_msb()) << 7
+ | (0x7F & ev.pitch_bender_lsb())),
+ evid);
+ } else if (ev.is_channel_pressure()) {
+ append_control_unlocked(
+ Evoral::MIDI::ChannelPressure(ev.event_type(), 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());
+ for (size_t i=0; i < ev.size(); ++i) {
+ printf("%X ", ev.buffer()[i]);
+ }
+ printf("\n");
+ } else {
+ printf("WARNING: Sequence: Unknown MIDI event type %X\n", ev.type());
+ }
+
+ _edited = true;
+}