summaryrefslogtreecommitdiff
path: root/gtk2_ardour
diff options
context:
space:
mode:
authorHans Baier <hansfbaier@googlemail.com>2008-12-25 23:08:57 +0000
committerHans Baier <hansfbaier@googlemail.com>2008-12-25 23:08:57 +0000
commitbe75d43bd0e6a5ced684e95bf7e753f42d88bd21 (patch)
treefe09e7508ea4e71861375f86fc4e6fce03472ee7 /gtk2_ardour
parentc3636a8c61401c2e487313566348e0f6d1fab990 (diff)
* 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
Diffstat (limited to 'gtk2_ardour')
-rw-r--r--gtk2_ardour/editor.cc7
-rw-r--r--gtk2_ardour/editor.h2
-rw-r--r--gtk2_ardour/midi_region_view.cc31
-rw-r--r--gtk2_ardour/midi_region_view.h10
-rw-r--r--gtk2_ardour/public_editor.h4
5 files changed, 45 insertions, 9 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<Evoral::Note> note)
+{
+ if (!trackview.editor.is_midi_sound_notes_active()) {
+ cerr << "not_active " << endl;
+ return;
+ }
+
+ RouteUI* route_ui = dynamic_cast<RouteUI*> (&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<Evoral::Note> note)
+{
+ RouteUI* route_ui = dynamic_cast<RouteUI*> (&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<Evoral::Note> 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<Evoral::Note> note);
+
void clear_events();
void switch_source(boost::shared_ptr<ARDOUR::Source> 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,