Remove internal edit mode and add "content" tool.
[ardour.git] / gtk2_ardour / step_editor.cc
index 45e286dc709601f0030183f81d0060cf479e4efd..ec525b84ed71a019be92c5be7406459fc66b98e5 100644 (file)
@@ -1,3 +1,22 @@
+/*
+    Copyright (C) 2012 Paul Davis 
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
 #include "ardour/midi_track.h"
 #include "ardour/midi_region.h"
 #include "ardour/tempo.h"
@@ -22,7 +41,7 @@ StepEditor::StepEditor (PublicEditor& e, boost::shared_ptr<MidiTrack> t, MidiTim
        step_edit_insert_position = 0;
         _step_edit_triplet_countdown = 0;
         _step_edit_within_chord = 0;
-        _step_edit_chord_duration = 0.0;
+        _step_edit_chord_duration = Evoral::MusicalTime();
         step_edit_region_view = 0;
 
         _track->PlaylistChanged.connect (*this, invalidator (*this),
@@ -41,11 +60,11 @@ StepEditor::start_step_editing ()
 {
         _step_edit_triplet_countdown = 0;
         _step_edit_within_chord = 0;
-        _step_edit_chord_duration = 0.0;
+        _step_edit_chord_duration = Evoral::MusicalTime();
         step_edit_region.reset ();
         step_edit_region_view = 0;
         last_added_pitch = -1;
-        last_added_end = 0;
+        last_added_end = Evoral::MusicalTime();
 
         resync_step_edit_position ();
         prepare_step_edit_region ();
@@ -63,7 +82,6 @@ StepEditor::start_step_editing ()
         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 ();
 }
 
@@ -131,7 +149,7 @@ bool
 StepEditor::step_editor_hidden (GdkEventAny*)
 {
         step_editor_hide ();
-        return true;
+        return true; // XXX remember position ?!
 }
 
 void
@@ -180,7 +198,7 @@ StepEditor::check_step_edit ()
                incoming.read_contents (size, buf);
 
                if ((buf[0] & 0xf0) == MIDI_CMD_NOTE_ON) {
-                        step_add_note (buf[0] & 0xf, buf[1], buf[2], 0.0);
+                       step_add_note (buf[0] & 0xf, buf[1], buf[2], Evoral::MusicalTime());
                }
        }
 }
@@ -215,7 +233,7 @@ StepEditor::move_step_edit_beat_pos (Evoral::MusicalTime beats)
                 if (-beats < step_edit_beat_pos) {
                         step_edit_beat_pos += beats; // its negative, remember
                 } else {
-                        step_edit_beat_pos = 0;
+                        step_edit_beat_pos = Evoral::MusicalTime();
                 }
         }
         step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos);
@@ -237,7 +255,9 @@ StepEditor::step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, Evo
         assert (step_edit_region);
         assert (step_edit_region_view);
 
-        if (beat_duration == 0.0) {
+        if (beat_duration == 0.0 && step_editor) {
+                beat_duration = step_editor->note_length();
+        } else if (beat_duration == 0.0) {
                 bool success;
                 beat_duration = _editor.get_grid_type_as_beats (success, step_edit_insert_position);
 
@@ -259,8 +279,8 @@ StepEditor::step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, Evo
 
         framepos_t fpos = step_edit_region_view->region_beats_to_absolute_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));
+        if (fpos >= (_editor.leftmost_sample() + _editor.current_page_samples())) {
+                _editor.reset_x_origin (fpos - (_editor.current_page_samples()/4));
         }
 
         Evoral::MusicalTime at = step_edit_beat_pos;
@@ -272,8 +292,8 @@ StepEditor::step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, Evo
                    up by 1 tick from where the last note ended
                 */
 
-                at += 1.0/Timecode::BBT_Time::ticks_per_beat;
-                len -= 1.0/Timecode::BBT_Time::ticks_per_beat;
+               at  += Evoral::MusicalTime::ticks(1);
+               len -= Evoral::MusicalTime::ticks(1);
         }
 
         step_edit_region_view->step_add_note (channel, pitch, velocity, at, len);
@@ -293,7 +313,7 @@ StepEditor::step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, Evo
                 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/Timecode::BBT_Time::ticks_per_beat; // tiny, but no longer overlapping
+                step_edit_beat_pos += Evoral::MusicalTime::ticks(1); // tiny, but no longer overlapping
                 _step_edit_chord_duration = max (_step_edit_chord_duration, beat_duration);
         }
 
@@ -364,7 +384,7 @@ StepEditor::step_edit_rest (Evoral::MusicalTime beats)
 void
 StepEditor::step_edit_beat_sync ()
 {
-        step_edit_beat_pos = ceil (step_edit_beat_pos);
+        step_edit_beat_pos = step_edit_beat_pos.round_up_to_beat();
         step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos);
 }
 
@@ -378,8 +398,8 @@ StepEditor::step_edit_bar_sync ()
         }
 
         framepos_t fpos = step_edit_region_view->region_beats_to_absolute_frames (step_edit_beat_pos);
-        fpos = _session->tempo_map().round_to_bar (fpos, 1);
-        step_edit_beat_pos = ceil (step_edit_region_view->region_frames_to_region_beats (fpos - step_edit_region->position()));
+        fpos = _session->tempo_map().round_to_bar (fpos, RoundUpAlways);
+        step_edit_beat_pos = step_edit_region_view->region_frames_to_region_beats (fpos - step_edit_region->position()).round_up_to_beat();
         step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos);
 }
 
@@ -388,7 +408,7 @@ StepEditor::playlist_changed ()
 {
         step_edit_region_connection.disconnect ();
         _track->playlist()->RegionRemoved.connect (step_edit_region_connection, invalidator (*this),
-                                                   ui_bind (&StepEditor::region_removed, this, _1),
+                                                   boost::bind (&StepEditor::region_removed, this, _1),
                                                    gui_context());
 }
 
@@ -405,7 +425,7 @@ StepEditor::region_removed (boost::weak_ptr<Region> wr)
                 step_edit_region.reset();
                 step_edit_region_view = 0;
                 // force a recompute of the insert position
-                step_edit_beat_pos = -1.0;
+                step_edit_beat_pos = Evoral::MusicalTime(-1);
         }
 }