make step entry chord & triplet buttons do their thing, or something close to it
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 3 Aug 2010 04:13:05 +0000 (04:13 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 3 Aug 2010 04:13:05 +0000 (04:13 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7530 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/midi_time_axis.cc
gtk2_ardour/midi_time_axis.h
gtk2_ardour/step_entry.cc
gtk2_ardour/step_entry.h

index 89a138f8b96197d3575df18135603620978a2a9a..0287a1c0ea82da7f33b9793995b0a05ba517b1df 100644 (file)
@@ -909,6 +909,10 @@ MidiTimeAxisView::start_step_editing ()
 {
        step_edit_insert_position = _editor.get_preferred_edit_position ();
         step_edit_beat_pos = -1.0;
+        _step_edit_triplet_countdown = 0;
+        _step_edit_within_chord = 0;
+        _step_edit_chord_duration = 0.0;
+
        step_edit_region = playlist()->top_region_at (step_edit_insert_position);
 
        if (step_edit_region) {
@@ -989,14 +993,63 @@ MidiTimeAxisView::step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocit
                                 return -1;
                         }
                 }
-                                
+
                 step_edit_region_view->step_add_note (channel, pitch, velocity, step_edit_beat_pos, beat_duration);
-                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;
+                } else {
+                        step_edit_beat_pos += 1.0/Meter::ticks_per_beat; // tiny, but no longer overlapping
+                        _step_edit_chord_duration = beat_duration;
+                }
         }
 
         return 0;
 }
 
+bool
+MidiTimeAxisView::step_edit_within_triplet() const
+{
+        return _step_edit_triplet_countdown > 0;
+}
+
+bool
+MidiTimeAxisView::step_edit_within_chord() const
+{
+        return _step_edit_within_chord;
+}
+
+void
+MidiTimeAxisView::step_edit_toggle_triplet ()
+{
+        if (_step_edit_triplet_countdown == 0) {
+                _step_edit_within_chord = false;
+                _step_edit_triplet_countdown = 3;
+        } else {
+                _step_edit_triplet_countdown = 0;
+        }
+}
+
+void
+MidiTimeAxisView::step_edit_toggle_chord ()
+{
+        if (_step_edit_within_chord) {
+                _step_edit_within_chord = false;
+                step_edit_beat_pos += _step_edit_chord_duration;
+        } else {
+                _step_edit_triplet_countdown = 0;
+                _step_edit_within_chord = true;
+        }
+}
+
 void
 MidiTimeAxisView::step_edit_rest ()
 {
index 2c0c8b2d44c72a385e994e3052a9900003c9a42a..fe1835266f56b495ae41092b554ee287a0c496af 100644 (file)
@@ -91,8 +91,12 @@ class MidiTimeAxisView : public RouteTimeAxisView
        void stop_step_editing ();
        void check_step_edit ();
        void step_edit_rest ();
-        int step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, 
-                           Evoral::MusicalTime beat_duration);
+        int  step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, 
+                            Evoral::MusicalTime beat_duration);
+        bool step_edit_within_triplet () const;
+        void step_edit_toggle_triplet ();
+        bool step_edit_within_chord () const;
+        void step_edit_toggle_chord ();
 
        const MidiMultipleChannelSelector& channel_selector() { return _channel_selector; }
 
@@ -138,6 +142,9 @@ class MidiTimeAxisView : public RouteTimeAxisView
        Evoral::MusicalTime step_edit_beat_pos;
        boost::shared_ptr<ARDOUR::Region> step_edit_region;
        MidiRegionView* step_edit_region_view;
+        uint8_t _step_edit_triplet_countdown;
+        bool    _step_edit_within_chord;
+        Evoral::MusicalTime _step_edit_chord_duration;
         void region_removed (boost::weak_ptr<ARDOUR::Region>);
         void playlist_changed ();
         PBD::ScopedConnection step_edit_region_connection;
index aa81fead3d36e09900a34fd9bd872b95287d5b4b..666890996b5b0b5fe873ace379136bd77640fbd0 100644 (file)
@@ -17,6 +17,8 @@
 
 */
 
+#include <iostream>
+
 #include "midi_time_axis.h"
 #include "step_entry.h"
 #include "utils.h"
@@ -169,6 +171,8 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv)
        g_signal_connect(G_OBJECT(_piano), "note-off", G_CALLBACK(_note_off_event_handler), this);
 
         rest_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::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));
 
         packer.set_spacing (6);
         packer.pack_start (upper_box, false, false);
@@ -226,14 +230,11 @@ StepEntry::note_off_event_handler (int note)
                 velocity = 127;
         }
 
-        if (!triplet_button.get_active()) {
-                _mtv->step_add_note (channel_adjustment.get_value(), note, velocity, length);
-        } else {
+        if (_mtv->step_edit_within_triplet()) {
                 length *= 2.0/3.0;
-                _mtv->step_add_note (channel_adjustment.get_value(), note, velocity, length);
-                _mtv->step_add_note (channel_adjustment.get_value(), note, velocity, length);
-                _mtv->step_add_note (channel_adjustment.get_value(), note, velocity, length);
         }
+
+        _mtv->step_add_note (channel_adjustment.get_value(), note, velocity, length);
 }
 
 void
@@ -241,3 +242,19 @@ StepEntry::rest_click ()
 {
         _mtv->step_edit_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 ();
+        }
+}
index cabd9eba478f2d5b0514ed2768cd3e2913514eef..d57ac3fadf659992ce5db62138d53ad14d96d4a0 100644 (file)
@@ -79,6 +79,8 @@ class StepEntry : public ArdourDialog
 
         void rest_click ();
         void sustain_click ();
+        void chord_toggled ();
+        void triplet_toggled ();
 };
 
 #endif /* __gtk2_ardour_step_entry_h__ */