From be75d43bd0e6a5ced684e95bf7e753f42d88bd21 Mon Sep 17 00:00:00 2001 From: Hans Baier Date: Thu, 25 Dec 2008 23:08:57 +0000 Subject: [PATCH] * first prototype implementation of playing back MIDI notes when selected git-svn-id: svn://localhost/ardour2/branches/3.0@4348 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/editor.cc | 7 ------- gtk2_ardour/editor.h | 2 +- gtk2_ardour/midi_region_view.cc | 31 +++++++++++++++++++++++++++++++ gtk2_ardour/midi_region_view.h | 10 +++++++++- gtk2_ardour/public_editor.h | 4 ++++ libs/ardour/midi_track.cc | 4 ++-- 6 files changed, 47 insertions(+), 11 deletions(-) diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 9740c8857c..0bca31a6b8 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -3248,11 +3248,6 @@ Editor::midi_panic_button_pressed () } } -void Editor::midi_sound_notes_toggled () -{ - cerr << "toggle sound notes" << endl; -} - void Editor::setup_midi_toolbar () { @@ -3317,8 +3312,6 @@ Editor::setup_midi_toolbar () midi_sound_notes.set_relief(Gtk::RELIEF_NONE); ARDOUR_UI::instance()->tooltips().set_tip (midi_sound_notes, _("Sound Notes")); midi_sound_notes.unset_flags (CAN_FOCUS); - midi_sound_notes.signal_toggled().connect (mem_fun(*this, - &Editor::midi_sound_notes_toggled)); /* Panic */ diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index a79b165ba1..834313f9ae 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -1754,7 +1754,7 @@ public: GroupedButtons *midi_tool_button_set; void midi_edit_mode_toggled (Editing::MidiEditMode m); void midi_panic_button_pressed (); - void midi_sound_notes_toggled(); + bool is_midi_sound_notes_active () const { return midi_sound_notes.get_active(); } bool ignore_midi_edit_mode_toggle; diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index cff4d358a8..9e8a7a8e29 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -887,6 +887,36 @@ MidiRegionView::extend_active_notes() } } +void +MidiRegionView::play_midi_note(boost::shared_ptr note) +{ + if (!trackview.editor.is_midi_sound_notes_active()) { + cerr << "not_active " << endl; + return; + } + + RouteUI* route_ui = dynamic_cast (&trackview); + assert(route_ui); + + route_ui->midi_track()->write_immediate_event(note->on_event().size(), note->on_event().buffer()); + + Glib::Thread::create(bind(mem_fun(this, &MidiRegionView::play_midi_note_off), note), false); + +} + +void +MidiRegionView::play_midi_note_off(boost::shared_ptr note) +{ + RouteUI* route_ui = dynamic_cast (&trackview); + assert(route_ui); + + Glib::usleep( + (note->off_event().time() - note->on_event().time()) * + (1000000 / route_ui->session().nominal_frame_rate()) + ); + route_ui->midi_track()->write_immediate_event(note->off_event().size(), note->off_event().buffer()); +} + /** Add a MIDI note to the view (with length). * @@ -1181,6 +1211,7 @@ MidiRegionView::note_selected(ArdourCanvas::CanvasNoteEvent* ev, bool add) } _selection.insert(ev); + play_midi_note(ev->note()); if ( ! ev->selected()) { ev->selected(true); diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index 2220dd9387..bffaf4ade2 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -261,7 +261,15 @@ class MidiRegionView : public RegionView void reset_width_dependent_items (double pixel_width); private: - + /** play back the given MIDI note immediately + */ + void play_midi_note(boost::shared_ptr note); + + /** play back the NoteOff-Event of the given note (used by + * @ref play_midi_note() ) after waiting the duration of the MIDI Note + */ + void play_midi_note_off(boost::shared_ptr note); + void clear_events(); void switch_source(boost::shared_ptr src); diff --git a/gtk2_ardour/public_editor.h b/gtk2_ardour/public_editor.h index 0af92a592a..a10539afe8 100644 --- a/gtk2_ardour/public_editor.h +++ b/gtk2_ardour/public_editor.h @@ -160,6 +160,10 @@ class PublicEditor : public Gtk::Window, public PBD::StatefulThingWithGoingAway * (defined in editing_syms.h) */ virtual Editing::MidiEditMode current_midi_edit_mode () const = 0; + + /** @return Sound edited notes in MIDI regions while editing + */ + virtual bool is_midi_sound_notes_active () const = 0; /** Possibly start the audition of a region. If \ref r is 0, or not an AudioRegion * any current audition is cancelled. If we are currently auditioning \ref r, diff --git a/libs/ardour/midi_track.cc b/libs/ardour/midi_track.cc index 0a253f3963..3be722d620 100644 --- a/libs/ardour/midi_track.cc +++ b/libs/ardour/midi_track.cc @@ -726,11 +726,11 @@ MidiTrack::midi_panic() bool MidiTrack::write_immediate_event(size_t size, const uint8_t* buf) { - /*printf("Write immediate event: "); + printf("Write immediate event: "); for (size_t i=0; i < size; ++i) { printf("%X ", buf[i]); } - printf("\n");*/ + printf("\n"); const uint32_t type = EventTypeMap::instance().midi_event_type(buf[0]); return (_immediate_events.write(0, type, size, buf) == size); }