diff --git a/gtk2_ardour/midi_time_axis.cc b/gtk2_ardour/midi_time_axis.cc index 1fddbe1f08..e62bd6223c 100644 --- a/gtk2_ardour/midi_time_axis.cc +++ b/gtk2_ardour/midi_time_axis.cc @@ -922,7 +922,12 @@ MidiTimeAxisView::start_step_editing () framecnt_t frames_from_start = _editor.get_preferred_edit_position() - step_edit_region->position(); - assert (frames_from_start >= 0); + 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); @@ -1097,6 +1102,8 @@ 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 @@ -1130,7 +1137,7 @@ MidiTimeAxisView::step_edit_bar_sync () return; } - nframes64_t fpos = step_edit_region->position() + + framepos_t fpos = step_edit_region->position() + step_edit_region_view->beats_to_frames (step_edit_beat_pos); fpos = _session->tempo_map().round_to_bar (fpos, 1); step_edit_beat_pos = ceil (step_edit_region_view->frames_to_beats (fpos - step_edit_region->position())); @@ -1145,11 +1152,9 @@ MidiTimeAxisView::add_region (framepos_t pos) real_editor->begin_reversible_command (_("create region")); playlist()->clear_history (); - framepos_t start = pos; - real_editor->snap_to (start, 0); - cerr << "Snap backwards from " << pos << " gave us " << start << endl; - const Meter& m = _session->tempo_map().meter_at(start); - const Tempo& t = _session->tempo_map().tempo_at(start); + real_editor->snap_to (pos, 0); + const Meter& m = _session->tempo_map().meter_at(pos); + const Tempo& t = _session->tempo_map().tempo_at(pos); double length = floor (m.frames_per_bar(t, _session->frame_rate())); boost::shared_ptr src = _session->create_midi_source_for_session (view()->trackview().track().get(), @@ -1162,7 +1167,7 @@ MidiTimeAxisView::add_region (framepos_t pos) boost::shared_ptr region = (RegionFactory::create (src, plist)); - playlist()->add_region (region, start); + playlist()->add_region (region, pos); _session->add_command (new StatefulDiffCommand (playlist())); real_editor->commit_reversible_command(); diff --git a/gtk2_ardour/step_editing.bindings b/gtk2_ardour/step_editing.bindings index d7e8df14b1..59a3b2e4d6 100644 --- a/gtk2_ardour/step_editing.bindings +++ b/gtk2_ardour/step_editing.bindings @@ -1,7 +1,58 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gtk2_ardour/step_entry.cc b/gtk2_ardour/step_entry.cc index 7787ec006d..7481565363 100644 --- a/gtk2_ardour/step_entry.cc +++ b/gtk2_ardour/step_entry.cc @@ -67,7 +67,7 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv) , grid_rest_button (_("g-rest")) , channel_adjustment (1, 1, 16, 1, 4) , channel_spinner (channel_adjustment) - , octave_adjustment (0, 1, 11, 1, 4) + , octave_adjustment (4, 1, 11, 1, 4) // start in octave 4 , octave_spinner (octave_adjustment) , length_divisor_adjustment (1.0, 1.0, 128, 1.0, 4.0) , length_divisor_spinner (length_divisor_adjustment) @@ -309,6 +309,25 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv) ARDOUR_UI::instance()->set_tip (&bank_button, _("Insert a bank change message"), ""); ARDOUR_UI::instance()->set_tip (&program_button, _("Insert a program change message"), ""); + 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/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()); + 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()); + act = myactions.find_action ("StepEditing/insert-rest"); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (rest_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (rest_button.gobj()), act->gobj()); + act = myactions.find_action ("StepEditing/insert-snap-rest"); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (grid_rest_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (grid_rest_button.gobj()), act->gobj()); + act = myactions.find_action ("StepEditing/sustain"); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (sustain_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (sustain_button.gobj()), act->gobj()); + upper_box.set_spacing (6); upper_box.pack_start (chord_button, false, false); upper_box.pack_start (note_length_box, false, false, 12); @@ -378,10 +397,6 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv) program_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::program_click)); bank_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::bank_click)); - rest_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::rest_click)); - grid_rest_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::grid_rest_click)); - chord_button.signal_toggled().connect (sigc::mem_fun (*this, &StepEntry::chord_toggled)); - triplet_button.signal_toggled().connect (sigc::mem_fun (*this, &StepEntry::triplet_toggled)); beat_resync_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::beat_resync_click)); bar_resync_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::bar_resync_click)); @@ -432,10 +447,6 @@ StepEntry::on_key_press_event (GdkEventKey* ev) bool StepEntry::on_key_release_event (GdkEventKey* ev) { - /* focus widget gets first shot, then bindings, otherwise - forward to main window - */ - if (!gtk_window_propagate_key_event (GTK_WINDOW(gobj()), ev)) { KeyboardKey k (ev->state, ev->keyval); @@ -443,8 +454,10 @@ StepEntry::on_key_release_event (GdkEventKey* ev) return true; } } + + /* don't forward releases */ - return forward_key_press (ev); + return true; } void @@ -454,9 +467,27 @@ StepEntry::rest_event_handler () } Evoral::MusicalTime -StepEntry::note_length () const +StepEntry::note_length () { - return 1.0 / (Evoral::MusicalTime) length_divisor_adjustment.get_value(); + Evoral::MusicalTime base_time = 1.0 / (Evoral::MusicalTime) length_divisor_adjustment.get_value(); + + RefPtr act = myactions.find_action ("StepEditing/toggle-triplet"); + 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 + } + + return base_time; } uint8_t @@ -477,39 +508,12 @@ StepEntry::note_off_event_handler (int note) insert_note (note); } -void -StepEntry::rest_click () -{ - insert_rest (); -} - -void -StepEntry::grid_rest_click () -{ - insert_grid_rest (); -} - -void -StepEntry::triplet_toggled () -{ - if (triplet_button.get_active () != _mtv->step_edit_within_triplet()) { - _mtv->step_edit_toggle_triplet (); - } -} - -void -StepEntry::chord_toggled () -{ - if (chord_button.get_active() != _mtv->step_edit_within_chord ()) { - _mtv->step_edit_toggle_chord (); - } -} void StepEntry::on_show () { ArdourDialog::on_show (); - piano->grab_focus (); + //piano->grab_focus (); } void @@ -542,6 +546,37 @@ StepEntry::register_actions () myactions.register_action ("StepEditing", "insert-g", _("Insert Note G"), sigc::mem_fun (*this, &StepEntry::insert_g)); myactions.register_action ("StepEditing", "insert-gsharp", _("Insert Note G-sharp"), sigc::mem_fun (*this, &StepEntry::insert_gsharp)); + myactions.register_action ("StepEditing", "insert-rest", _("Insert a Note-length Rest"), sigc::mem_fun (*this, &StepEntry::insert_rest)); + myactions.register_action ("StepEditing", "insert-snap-rest", _("Insert a Snap-length Rest"), sigc::mem_fun (*this, &StepEntry::insert_grid_rest)); + + myactions.register_action ("StepEditing", "next-octave", _("Move to next octave"), sigc::mem_fun (*this, &StepEntry::next_octave)); + myactions.register_action ("StepEditing", "prev-octave", _("Move to next octave"), sigc::mem_fun (*this, &StepEntry::prev_octave)); + + myactions.register_action ("StepEditing", "next-note-length", _("Move to Next Note Length"), sigc::mem_fun (*this, &StepEntry::next_note_length)); + myactions.register_action ("StepEditing", "prev-note-length", _("Move to Previous Note Length"), sigc::mem_fun (*this, &StepEntry::prev_note_length)); + + myactions.register_action ("StepEditing", "inc-note-length", _("Increase Note Length"), sigc::mem_fun (*this, &StepEntry::inc_note_length)); + myactions.register_action ("StepEditing", "dec-note-length", _("Decrease Note Length"), sigc::mem_fun (*this, &StepEntry::dec_note_length)); + + myactions.register_action ("StepEditing", "next-note-velocity", _("Move to Next Note Velocity"), sigc::mem_fun (*this, &StepEntry::next_note_velocity)); + myactions.register_action ("StepEditing", "prev-note-velocity", _("Move to Previous Note Velocity"), sigc::mem_fun (*this, &StepEntry::prev_note_velocity)); + + myactions.register_action ("StepEditing", "inc-note-velocity", _("Increase Note Velocity"), sigc::mem_fun (*this, &StepEntry::inc_note_velocity)); + myactions.register_action ("StepEditing", "dec-note-velocity", _("Decrease Note Velocity"), sigc::mem_fun (*this, &StepEntry::dec_note_velocity)); + + myactions.register_action ("StepEditing", "octave-0", _("Switch to the 1st octave"), sigc::mem_fun (*this, &StepEntry::octave_0)); + myactions.register_action ("StepEditing", "octave-1", _("Switch to the 2nd octave"), sigc::mem_fun (*this, &StepEntry::octave_1)); + myactions.register_action ("StepEditing", "octave-2", _("Switch to the 3rd octave"), sigc::mem_fun (*this, &StepEntry::octave_2)); + myactions.register_action ("StepEditing", "octave-3", _("Switch to the 4th octave"), sigc::mem_fun (*this, &StepEntry::octave_3)); + myactions.register_action ("StepEditing", "octave-4", _("Switch to the 5th octave"), sigc::mem_fun (*this, &StepEntry::octave_4)); + myactions.register_action ("StepEditing", "octave-5", _("Switch to the 6th octave"), sigc::mem_fun (*this, &StepEntry::octave_5)); + myactions.register_action ("StepEditing", "octave-6", _("Switch to the 7th octave"), sigc::mem_fun (*this, &StepEntry::octave_6)); + myactions.register_action ("StepEditing", "octave-7", _("Switch to the 8th octave"), sigc::mem_fun (*this, &StepEntry::octave_7)); + myactions.register_action ("StepEditing", "octave-8", _("Switch to the 9th octave"), sigc::mem_fun (*this, &StepEntry::octave_8)); + myactions.register_action ("StepEditing", "octave-9", _("Switch to the 10th octave"), sigc::mem_fun (*this, &StepEntry::octave_9)); + myactions.register_action ("StepEditing", "octave-10", _("Switch to the 11th octave"), sigc::mem_fun (*this, &StepEntry::octave_10)); + + RadioAction::Group note_length_group; myactions.register_radio_action ("StepEditing", note_length_group, "note-length-whole", @@ -577,11 +612,23 @@ StepEntry::register_actions () _("Set Note Velocity to Fortississimo"), sigc::mem_fun (*this, &StepEntry::note_velocity_change), 112); myactions.register_radio_action ("StepEditing", note_velocity_group, "note-velocity-fff", _("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)); + 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)); } void StepEntry::load_bindings () { + /* XXX move this to a better place */ + KeyboardKey::set_ignored_state (GDK_LOCK_MASK|GDK_MOD2_MASK|GDK_MOD3_MASK); + bindings.set_action_map (myactions); sys::path binding_file; @@ -592,6 +639,24 @@ StepEntry::load_bindings () } } +void +StepEntry::toggle_triplet () +{ + // nowt to be done +} + +void +StepEntry::toggle_chord () +{ + _mtv->step_edit_toggle_chord (); +} + +void +StepEntry::toggle_dotted () +{ + // nowt to be done +} + void StepEntry::program_click () { @@ -714,7 +779,6 @@ StepEntry::note_velocity_change (GtkAction* act) if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION(act))) { gint v = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (act)); - cerr << "Velocity reset to " << v << endl; velocity_adjustment.set_value (v); } } @@ -834,3 +898,136 @@ StepEntry::radio_button_release (GdkEventButton* ev, RadioButton* btn, int v) return false; } + +void +StepEntry::next_octave () +{ + octave_adjustment.set_value (octave_adjustment.get_value() + 1.0); +} + +void +StepEntry::prev_octave () +{ + octave_adjustment.set_value (octave_adjustment.get_value() - 1.0); +} + +void +StepEntry::inc_note_length () +{ + length_divisor_adjustment.set_value (length_divisor_adjustment.get_value() - 1.0); +} + +void +StepEntry::dec_note_length () +{ + length_divisor_adjustment.set_value (length_divisor_adjustment.get_value() + 1.0); +} + +void +StepEntry::prev_note_length () +{ + double l = length_divisor_adjustment.get_value(); + int il = (int) lrintf (l); // round to nearest integer + il = (il/2) * 2; // round to power of 2 + + if (il == 0) { + il = 1; + } + + il *= 2; // double + + length_divisor_adjustment.set_value (il); +} + +void +StepEntry::next_note_length () +{ + double l = length_divisor_adjustment.get_value(); + int il = (int) lrintf (l); // round to nearest integer + il = (il/2) * 2; // round to power of 2 + + if (il == 0) { + il = 1; + } + + il /= 2; // half + + if (il > 0) { + length_divisor_adjustment.set_value (il); + } +} + +void +StepEntry::inc_note_velocity () +{ + velocity_adjustment.set_value (velocity_adjustment.get_value() + 1.0); +} + +void +StepEntry::dec_note_velocity () +{ + velocity_adjustment.set_value (velocity_adjustment.get_value() - 1.0); +} + +void +StepEntry::next_note_velocity () +{ + double l = velocity_adjustment.get_value (); + + if (l < 16) { + l = 16; + } else if (l < 32) { + l = 32; + } else if (l < 48) { + l = 48; + } else if (l < 64) { + l = 64; + } else if (l < 80) { + l = 80; + } else if (l < 96) { + l = 96; + } else if (l < 112) { + l = 112; + } else if (l < 127) { + l = 127; + } + + velocity_adjustment.set_value (l); +} + +void +StepEntry::prev_note_velocity () +{ + double l = velocity_adjustment.get_value (); + + if (l > 112) { + l = 112; + } else if (l > 96) { + l = 96; + } else if (l > 80) { + l = 80; + } else if (l > 64) { + l = 64; + } else if (l > 48) { + l = 48; + } else if (l > 32) { + l = 32; + } else if (l > 16) { + l = 16; + } else { + l = 1; + } + + velocity_adjustment.set_value (l); +} + +void +StepEntry::octave_n (int n) +{ + octave_adjustment.set_value (n); +} + +void +StepEntry::do_sustain () +{ +} diff --git a/gtk2_ardour/step_entry.h b/gtk2_ardour/step_entry.h index 0fd7d6f121..c627b9575f 100644 --- a/gtk2_ardour/step_entry.h +++ b/gtk2_ardour/step_entry.h @@ -41,7 +41,7 @@ class StepEntry : public ArdourDialog void note_off_event_handler (int note); void rest_event_handler (); - Evoral::MusicalTime note_length() const; + Evoral::MusicalTime note_length(); uint8_t note_velocity() const; uint8_t note_channel() const; @@ -119,11 +119,6 @@ class StepEntry : public ArdourDialog void bank_click (); void program_click (); - void rest_click (); - void grid_rest_click (); - void sustain_click (); - void chord_toggled (); - void triplet_toggled (); void beat_resync_click (); void bar_resync_click (); @@ -163,6 +158,38 @@ class StepEntry : public ArdourDialog void load_bindings (); Gtkmm2ext::Bindings bindings; + + void inc_note_velocity (); + void dec_note_velocity (); + void next_note_velocity (); + void prev_note_velocity (); + + void inc_note_length (); + void dec_note_length (); + void next_note_length (); + void prev_note_length (); + + void next_octave (); + void prev_octave (); + + void octave_n (int n); + void octave_0 () { octave_n (0); } + void octave_1 () { octave_n (1); } + void octave_2 () { octave_n (2); } + void octave_3 () { octave_n (3); } + void octave_4 () { octave_n (4); } + void octave_5 () { octave_n (5); } + void octave_6 () { octave_n (6); } + void octave_7 () { octave_n (7); } + void octave_8 () { octave_n (8); } + void octave_9 () { octave_n (9); } + void octave_10 () { octave_n (10); } + + void toggle_dotted(); + void toggle_triplet(); + void toggle_chord(); + + void do_sustain (); }; #endif /* __gtk2_ardour_step_entry_h__ */ diff --git a/libs/gtkmm2ext/bindings.cc b/libs/gtkmm2ext/bindings.cc index af709b49b6..12c37f1095 100644 --- a/libs/gtkmm2ext/bindings.cc +++ b/libs/gtkmm2ext/bindings.cc @@ -10,6 +10,24 @@ using namespace Glib; using namespace Gtk; using namespace Gtkmm2ext; +uint32_t KeyboardKey::_ignored_state = 0; + +KeyboardKey::KeyboardKey (uint32_t state, uint32_t keycode) +{ + uint32_t ignore = _ignored_state; + + if (gdk_keyval_is_upper (keycode) && gdk_keyval_is_lower (keycode)) { + /* key is not subject to case, so ignore SHIFT + */ + ignore |= GDK_SHIFT_MASK; + } + + _val = (state & ~ignore); + _val <<= 32; + _val |= keycode; +}; + + string KeyboardKey::name () const { @@ -126,7 +144,6 @@ Bindings::activate (KeyboardKey kb, KeyboardKey::Operation op) /* lets do it ... */ - cerr << "Firing up " << k->second->get_name() << endl; k->second->activate (); return true; } @@ -150,6 +167,7 @@ Bindings::add (KeyboardKey kb, KeyboardKey::Operation op, RefPtr what) if (k == kbm->end()) { pair > newpair (kb, what); kbm->insert (newpair); + cerr << "Bindings added " << kb.key() << " w/ " << kb.state() << endl; } else { k->second = what; } diff --git a/libs/gtkmm2ext/gtkmm2ext/bindings.h b/libs/gtkmm2ext/gtkmm2ext/bindings.h index 6959dc82e1..45c3cfd809 100644 --- a/libs/gtkmm2ext/gtkmm2ext/bindings.h +++ b/libs/gtkmm2ext/gtkmm2ext/bindings.h @@ -23,14 +23,10 @@ class KeyboardKey _val = GDK_VoidSymbol; } - KeyboardKey (int state, int keycode) { - _val = state; - _val <<= 32; - _val |= keycode; - }; + KeyboardKey (uint32_t state, uint32_t keycode); - int state() const { return _val >> 32; } - int key() const { return _val & 0xffff; } + uint32_t state() const { return _val >> 32; } + uint32_t key() const { return _val & 0xffff; } bool operator<(const KeyboardKey& other) const { return _val < other._val; @@ -42,9 +38,13 @@ class KeyboardKey std::string name() const; static bool make_key (const std::string&, KeyboardKey&); - + static void set_ignored_state (int mask) { + _ignored_state = mask; + } + private: uint64_t _val; + static uint32_t _ignored_state; }; class ActionMap {