From d6166084b1b2fdf75f1f6942ed74c78f759a938b Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 13 Aug 2010 21:48:31 +0000 Subject: [PATCH] step editor: add double, triple dotted note support + back + resync-to-ep buttons git-svn-id: svn://localhost/ardour2/branches/3.0@7623 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/midi_time_axis.cc | 178 ++++++++++++++++++++---------- gtk2_ardour/midi_time_axis.h | 5 + gtk2_ardour/step_editing.bindings | 1 + gtk2_ardour/step_entry.cc | 146 +++++++++++++++++++++--- gtk2_ardour/step_entry.h | 17 ++- 5 files changed, 269 insertions(+), 78 deletions(-) diff --git a/gtk2_ardour/midi_time_axis.cc b/gtk2_ardour/midi_time_axis.cc index 464ed630f5..3eb7fff692 100644 --- a/gtk2_ardour/midi_time_axis.cc +++ b/gtk2_ardour/midi_time_axis.cc @@ -257,6 +257,7 @@ MidiTimeAxisView::region_removed (boost::weak_ptr wr) if (step_edit_region == r) { step_edit_region.reset(); + step_edit_region_view = 0; // force a recompute of the insert position step_edit_beat_pos = -1.0; } @@ -894,11 +895,50 @@ MidiTimeAxisView::route_active_changed () void MidiTimeAxisView::start_step_editing () { - step_edit_insert_position = _editor.get_preferred_edit_position (); _step_edit_triplet_countdown = 0; _step_edit_within_chord = 0; _step_edit_chord_duration = 0.0; - + step_edit_region.reset (); + step_edit_region_view = 0; + + resync_step_edit_position (); + prepare_step_edit_region (); + reset_step_edit_beat_pos (); + + assert (step_edit_region); + assert (step_edit_region_view); + + if (step_editor == 0) { + step_editor = new StepEntry (*this); + step_editor->signal_delete_event().connect (sigc::mem_fun (*this, &MidiTimeAxisView::step_editor_hidden)); + step_editor->signal_hide().connect (sigc::mem_fun (*this, &MidiTimeAxisView::step_editor_hide)); + } + + step_edit_region_view->show_step_edit_cursor (step_edit_beat_pos); + step_edit_region_view->set_step_edit_cursor_width (step_editor->note_length()); + + step_editor->set_position (WIN_POS_MOUSE); + step_editor->present (); +} + +void +MidiTimeAxisView::resync_step_edit_position () +{ + step_edit_insert_position = _editor.get_preferred_edit_position (); +} + +void +MidiTimeAxisView::resync_step_edit_to_edit_point () +{ + resync_step_edit_position (); + if (step_edit_region) { + reset_step_edit_beat_pos (); + } +} + +void +MidiTimeAxisView::prepare_step_edit_region () +{ boost::shared_ptr r = playlist()->top_region_at (step_edit_insert_position); if (r) { @@ -914,32 +954,26 @@ MidiTimeAxisView::start_step_editing () RegionView* rv = view()->find_view (step_edit_region); step_edit_region_view = dynamic_cast(rv); } +} + +void +MidiTimeAxisView::reset_step_edit_beat_pos () +{ assert (step_edit_region); assert (step_edit_region_view); - if (step_editor == 0) { - step_editor = new StepEntry (*this); - step_editor->signal_delete_event().connect (sigc::mem_fun (*this, &MidiTimeAxisView::step_editor_hidden)); - step_editor->signal_hide().connect (sigc::mem_fun (*this, &MidiTimeAxisView::step_editor_hide)); - } - framecnt_t frames_from_start = _editor.get_preferred_edit_position() - step_edit_region->position(); - + if (frames_from_start < 0) { /* this can happen with snap enabled, and the edit point == Playhead. we snap the position of the new region, and it can end up after the edit point. */ frames_from_start = 0; } - + step_edit_beat_pos = step_edit_region_view->frames_to_beats (frames_from_start); - - step_edit_region_view->show_step_edit_cursor (step_edit_beat_pos); - step_edit_region_view->set_step_edit_cursor_width (step_editor->note_length()); - - step_editor->set_position (WIN_POS_MOUSE); - step_editor->present (); + step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos); } bool @@ -1020,56 +1054,82 @@ MidiTimeAxisView::step_edit_sustain (Evoral::MusicalTime beats) } } +void +MidiTimeAxisView::move_step_edit_beat_pos (Evoral::MusicalTime beats) +{ + if (beats > 0.0) { + step_edit_beat_pos = min (step_edit_beat_pos + beats, + step_edit_region_view->frames_to_beats (step_edit_region->length())); + } else if (beats < 0.0) { + if (beats < step_edit_beat_pos) { + step_edit_beat_pos += beats; // its negative, remember + } else { + step_edit_beat_pos = 0; + } + } + step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos); +} + int MidiTimeAxisView::step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, Evoral::MusicalTime beat_duration) { - if (step_edit_region && step_edit_region_view) { + /* do these things in case undo removed the step edit region + */ + if (!step_edit_region) { + resync_step_edit_position (); + prepare_step_edit_region (); + reset_step_edit_beat_pos (); + step_edit_region_view->show_step_edit_cursor (step_edit_beat_pos); + step_edit_region_view->set_step_edit_cursor_width (step_editor->note_length()); + } + + assert (step_edit_region); + assert (step_edit_region_view); - if (beat_duration == 0.0) { - bool success; - beat_duration = _editor.get_grid_type_as_beats (success, step_edit_insert_position); - - if (!success) { - return -1; - } - } - - MidiStreamView* msv = midi_view(); + if (beat_duration == 0.0) { + bool success; + beat_duration = _editor.get_grid_type_as_beats (success, step_edit_insert_position); - /* make sure its visible on the vertical axis */ + if (!success) { + return -1; + } + } + + MidiStreamView* msv = midi_view(); + + /* make sure its visible on the vertical axis */ + + if (pitch < msv->lowest_note() || pitch > msv->highest_note()) { + msv->update_note_range (pitch); + msv->set_note_range (MidiStreamView::ContentsRange); + } + + /* make sure its visible on the horizontal axis */ + + nframes64_t fpos = step_edit_region->position() + + step_edit_region_view->beats_to_frames (step_edit_beat_pos + beat_duration); + + if (fpos >= (_editor.leftmost_position() + _editor.current_page_frames())) { + _editor.reset_x_origin (fpos - (_editor.current_page_frames()/4)); + } + + step_edit_region_view->step_add_note (channel, pitch, velocity, step_edit_beat_pos, beat_duration); + + if (_step_edit_triplet_countdown > 0) { + _step_edit_triplet_countdown--; - if (pitch < msv->lowest_note() || pitch > msv->highest_note()) { - msv->update_note_range (pitch); - msv->set_note_range (MidiStreamView::ContentsRange); - } - - /* make sure its visible on the horizontal axis */ - - nframes64_t fpos = step_edit_region->position() + - step_edit_region_view->beats_to_frames (step_edit_beat_pos + beat_duration); - - if (fpos >= (_editor.leftmost_position() + _editor.current_page_frames())) { - _editor.reset_x_origin (fpos - (_editor.current_page_frames()/4)); - } - - step_edit_region_view->step_add_note (channel, pitch, velocity, step_edit_beat_pos, beat_duration); - - if (_step_edit_triplet_countdown > 0) { - _step_edit_triplet_countdown--; - - if (_step_edit_triplet_countdown == 0) { - _step_edit_triplet_countdown = 3; - } - } - - if (!_step_edit_within_chord) { - step_edit_beat_pos += beat_duration; - step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos); - } else { - step_edit_beat_pos += 1.0/Meter::ticks_per_beat; // tiny, but no longer overlapping - _step_edit_chord_duration = max (_step_edit_chord_duration, beat_duration); + if (_step_edit_triplet_countdown == 0) { + _step_edit_triplet_countdown = 3; } } + + if (!_step_edit_within_chord) { + step_edit_beat_pos += beat_duration; + step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos); + } else { + step_edit_beat_pos += 1.0/Meter::ticks_per_beat; // tiny, but no longer overlapping + _step_edit_chord_duration = max (_step_edit_chord_duration, beat_duration); + } return 0; } @@ -1116,8 +1176,6 @@ MidiTimeAxisView::step_edit_toggle_chord () _step_edit_triplet_countdown = 0; _step_edit_within_chord = true; } - - cerr << "Within chord now: " << _step_edit_within_chord << endl; } void diff --git a/gtk2_ardour/midi_time_axis.h b/gtk2_ardour/midi_time_axis.h index 8012db5cc1..63372b9218 100644 --- a/gtk2_ardour/midi_time_axis.h +++ b/gtk2_ardour/midi_time_axis.h @@ -100,6 +100,9 @@ class MidiTimeAxisView : public RouteTimeAxisView void step_edit_toggle_triplet (); bool step_edit_within_chord () const; void step_edit_toggle_chord (); + void reset_step_edit_beat_pos (); + void resync_step_edit_to_edit_point (); + void move_step_edit_beat_pos (Evoral::MusicalTime beats); void set_step_edit_cursor_width (Evoral::MusicalTime beats); const MidiMultipleChannelSelector& channel_selector() { return _channel_selector; } @@ -184,6 +187,8 @@ class MidiTimeAxisView : public RouteTimeAxisView StepEntry* step_editor; bool step_editor_hidden (GdkEventAny*); void step_editor_hide (); + void resync_step_edit_position (); + void prepare_step_edit_region (); }; #endif /* __ardour_midi_time_axis_h__ */ diff --git a/gtk2_ardour/step_editing.bindings b/gtk2_ardour/step_editing.bindings index 59a3b2e4d6..3bbb95bac2 100644 --- a/gtk2_ardour/step_editing.bindings +++ b/gtk2_ardour/step_editing.bindings @@ -53,6 +53,7 @@ + diff --git a/gtk2_ardour/step_entry.cc b/gtk2_ardour/step_entry.cc index 011fadc3c4..d3ecca434c 100644 --- a/gtk2_ardour/step_entry.cc +++ b/gtk2_ardour/step_entry.cc @@ -60,11 +60,14 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv) , _current_note_length (1.0) , _current_note_velocity (64) , triplet_button ("3") + , dot_adjustment (0.0, 0.0, 3.0, 1.0, 1.0) , beat_resync_button (_(">beat")) , bar_resync_button (_(">bar")) + , resync_button (_(">EP")) , sustain_button (_("sustain")) , rest_button (_("rest")) , grid_rest_button (_("g-rest")) + , back_button (_("back")) , channel_adjustment (1, 1, 16, 1, 4) , channel_spinner (channel_adjustment) , octave_adjustment (4, 1, 11, 1, 4) // start in octave 4 @@ -285,36 +288,78 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv) note_velocity_box.pack_start (velocity_fff_button, false, false); Label* l = manage (new Label); + l->set_markup ("-"); + l->show (); + dot0_button.add (*l); + + l = manage (new Label); l->set_markup ("."); l->show (); - dot_button.add (*l); + dot1_button.add (*l); + + l = manage (new Label); + l->set_markup (".."); + l->show (); + dot2_button.add (*l); + + l = manage (new Label); + l->set_markup ("..."); + l->show (); + dot3_button.add (*l); w = manage (new Image (::get_icon (X_("chord")))); w->show(); chord_button.add (*w); + dot_box1.pack_start (dot0_button, true, false); + dot_box1.pack_start (dot1_button, true, false); + dot_box2.pack_start (dot2_button, true, false); + dot_box2.pack_start (dot3_button, true, false); + rest_box.pack_start (rest_button, true, false); rest_box.pack_start (grid_rest_button, true, false); + rest_box.pack_start (back_button, true, false); resync_box.pack_start (beat_resync_button, true, false); resync_box.pack_start (bar_resync_button, true, false); + resync_box.pack_start (resync_button, true, false); ARDOUR_UI::instance()->set_tip (&chord_button, _("Stack inserted notes to form a chord"), ""); ARDOUR_UI::instance()->set_tip (&sustain_button, _("Extend selected notes by note length"), ""); - ARDOUR_UI::instance()->set_tip (&dot_button, _("Use dotted note lengths"), ""); + ARDOUR_UI::instance()->set_tip (&dot0_button, _("Use undotted note lengths"), ""); + ARDOUR_UI::instance()->set_tip (&dot1_button, _("Use dotted (* 1.5) note lengths"), ""); + ARDOUR_UI::instance()->set_tip (&dot2_button, _("Use double-dotted (* 1.75) note lengths"), ""); + ARDOUR_UI::instance()->set_tip (&dot3_button, _("Use triple-dotted (* 1.875) note lengths"), ""); ARDOUR_UI::instance()->set_tip (&rest_button, _("Insert a note-length's rest"), ""); ARDOUR_UI::instance()->set_tip (&grid_rest_button, _("Insert a grid-unit's rest"), ""); ARDOUR_UI::instance()->set_tip (&beat_resync_button, _("Insert a rest until the next beat"), ""); ARDOUR_UI::instance()->set_tip (&bar_resync_button, _("Insert a rest until the next bar"), ""); ARDOUR_UI::instance()->set_tip (&bank_button, _("Insert a bank change message"), ""); ARDOUR_UI::instance()->set_tip (&program_button, _("Insert a program change message"), ""); + ARDOUR_UI::instance()->set_tip (&back_button, _("Move Insert Position Back by Note Length"), ""); + ARDOUR_UI::instance()->set_tip (&resync_button, _("Move Insert Position to Edit Point"), ""); + act = myactions.find_action ("StepEditing/back"); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (back_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (back_button.gobj()), act->gobj()); + act = myactions.find_action ("StepEditing/sync-to-edit-point"); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (resync_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (resync_button.gobj()), act->gobj()); act = myactions.find_action ("StepEditing/toggle-triplet"); gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (triplet_button.gobj()), false); gtk_activatable_set_related_action (GTK_ACTIVATABLE (triplet_button.gobj()), act->gobj()); + act = myactions.find_action ("StepEditing/no-dotted"); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (dot0_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (dot0_button.gobj()), act->gobj()); act = myactions.find_action ("StepEditing/toggle-dotted"); - gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (dot_button.gobj()), false); - gtk_activatable_set_related_action (GTK_ACTIVATABLE (dot_button.gobj()), act->gobj()); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (dot1_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (dot1_button.gobj()), act->gobj()); + act = myactions.find_action ("StepEditing/toggle-double-dotted"); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (dot2_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (dot2_button.gobj()), act->gobj()); + act = myactions.find_action ("StepEditing/toggle-triple-dotted"); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (dot3_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (dot3_button.gobj()), act->gobj()); act = myactions.find_action ("StepEditing/toggle-chord"); gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (chord_button.gobj()), false); gtk_activatable_set_related_action (GTK_ACTIVATABLE (chord_button.gobj()), act->gobj()); @@ -332,7 +377,8 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv) upper_box.pack_start (chord_button, false, false); upper_box.pack_start (note_length_box, false, false, 12); upper_box.pack_start (triplet_button, false, false); - upper_box.pack_start (dot_button, false, false); + upper_box.pack_start (dot_box1, false, false); + upper_box.pack_start (dot_box2, false, false); upper_box.pack_start (sustain_button, false, false); upper_box.pack_start (rest_box, false, false); upper_box.pack_start (resync_box, false, false); @@ -386,6 +432,7 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv) velocity_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &StepEntry::velocity_value_change)); length_divisor_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &StepEntry::length_value_change)); + dot_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &StepEntry::dot_value_change)); _piano = (PianoKeyboard*) piano_keyboard_new (); piano = wrap ((GtkWidget*) _piano); @@ -475,16 +522,15 @@ StepEntry::note_length () RefPtr tact = RefPtr::cast_dynamic (act); bool triplets = tact->get_active (); - act = myactions.find_action ("StepEditing/toggle-dotted"); - tact = RefPtr::cast_dynamic (act); - bool dotted = tact->get_active (); - if (triplets) { base_time *= (2.0/3.0); } - if (dotted) { - base_time *= 1.5; // add support for multiple dots sometime + double dots = dot_adjustment.get_value (); + + if (dots > 0) { + dots = pow (2.0, dots); + base_time *= 1 + ((dots - 1.0)/dots); } return base_time; @@ -614,13 +660,28 @@ StepEntry::register_actions () _("Set Note Velocity to Fortississimo"), sigc::mem_fun (*this, &StepEntry::note_velocity_change), 127); myactions.register_toggle_action ("StepEditing", "toggle-triplet", _("Toggle Triple Notes"), - sigc::mem_fun (*this, &StepEntry::toggle_dotted)); - myactions.register_toggle_action ("StepEditing", "toggle-dotted", _("Toggled Dotted Notes"), sigc::mem_fun (*this, &StepEntry::toggle_triplet)); + + RadioAction::Group dot_group; + + myactions.register_radio_action ("StepEditing", dot_group, "no-dotted", _("No Dotted Notes"), + sigc::mem_fun (*this, &StepEntry::dot_change), 0); + myactions.register_radio_action ("StepEditing", dot_group, "toggle-dotted", _("Toggled Dotted Notes"), + sigc::mem_fun (*this, &StepEntry::dot_change), 1); + myactions.register_radio_action ("StepEditing", dot_group, "toggle-double-dotted", _("Toggled Double-Dotted Notes"), + sigc::mem_fun (*this, &StepEntry::dot_change), 2); + myactions.register_radio_action ("StepEditing", dot_group, "toggle-triple-dotted", _("Toggled Triple-Dotted Notes"), + sigc::mem_fun (*this, &StepEntry::dot_change), 3); + myactions.register_toggle_action ("StepEditing", "toggle-chord", _("Toggle Chord Entry"), sigc::mem_fun (*this, &StepEntry::toggle_chord)); myactions.register_action ("StepEditing", "sustain", _("Sustain Selected Notes by Note Length"), sigc::mem_fun (*this, &StepEntry::do_sustain)); + + myactions.register_action ("StepEditing", "sync-to-edit-point", _("Move Insert Position to Edit Point"), + sigc::mem_fun (*this, &StepEntry::sync_to_edit_point)); + myactions.register_action ("StepEditing", "back", _("Move Insert Position Back by Note Length"), + sigc::mem_fun (*this, &StepEntry::back)); } void @@ -642,7 +703,7 @@ StepEntry::load_bindings () void StepEntry::toggle_triplet () { - // nowt to be done + _mtv->set_step_edit_cursor_width (note_length()); } void @@ -652,9 +713,50 @@ StepEntry::toggle_chord () } void -StepEntry::toggle_dotted () +StepEntry::dot_change (GtkAction* act) { - // nowt to be done + if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION(act))) { + gint v = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (act)); + dot_adjustment.set_value (v); + } +} + +void +StepEntry::dot_value_change () +{ + RefPtr act; + RefPtr ract; + double val = dot_adjustment.get_value(); + bool inconsistent = true; + vector dot_actions; + + dot_actions.push_back ("StepEditing/no-dotted"); + dot_actions.push_back ("StepEditing/toggle-dotted"); + dot_actions.push_back ("StepEditing/toggle-double-dotted"); + dot_actions.push_back ("StepEditing/toggle-triple-dotted"); + + for (vector::iterator i = dot_actions.begin(); i != dot_actions.end(); ++i) { + + act = myactions.find_action (*i); + + if (act) { + ract = RefPtr::cast_dynamic (act); + + if (ract) { + if (ract->property_value() == val) { + ract->set_active (true); + inconsistent = false; + break; + } + } + } + } + + dot1_button.set_inconsistent (inconsistent); + dot2_button.set_inconsistent (inconsistent); + dot3_button.set_inconsistent (inconsistent); + + _mtv->set_step_edit_cursor_width (note_length()); } void @@ -1032,3 +1134,15 @@ StepEntry::do_sustain () { _mtv->step_edit_sustain (note_length()); } + +void +StepEntry::back () +{ + _mtv->move_step_edit_beat_pos (-note_length()); +} + +void +StepEntry::sync_to_edit_point () +{ + _mtv->resync_step_edit_to_edit_point (); +} diff --git a/gtk2_ardour/step_entry.h b/gtk2_ardour/step_entry.h index c627b9575f..934e5e5c18 100644 --- a/gtk2_ardour/step_entry.h +++ b/gtk2_ardour/step_entry.h @@ -58,18 +58,27 @@ class StepEntry : public ArdourDialog Gtk::ToggleButton chord_button; Gtk::ToggleButton triplet_button; - Gtk::ToggleButton dot_button; + Gtk::ToggleButton dot0_button; + Gtk::ToggleButton dot1_button; + Gtk::ToggleButton dot2_button; + Gtk::ToggleButton dot3_button; + Gtk::Adjustment dot_adjustment; + Gtk::VBox dot_box1; + Gtk::VBox dot_box2; Gtk::ToggleButton restart_button; Gtk::VBox resync_box; Gtk::Button beat_resync_button; Gtk::Button bar_resync_button; + Gtk::Button resync_button; Gtk::Button sustain_button; Gtk::Button rest_button; Gtk::Button grid_rest_button; Gtk::VBox rest_box; + Gtk::Button back_button; + Gtk::RadioButton length_1_button; Gtk::RadioButton length_2_button; Gtk::RadioButton length_4_button; @@ -185,11 +194,15 @@ class StepEntry : public ArdourDialog void octave_9 () { octave_n (9); } void octave_10 () { octave_n (10); } - void toggle_dotted(); + void dot_change (GtkAction*); + void dot_value_change (); + void toggle_triplet(); void toggle_chord(); void do_sustain (); + void back(); + void sync_to_edit_point (); }; #endif /* __gtk2_ardour_step_entry_h__ */