X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fstep_editor.cc;h=a65a7a861301a776179f87dac7deb8c33db7587e;hb=4c42a77441e74356cd909d994e270d1e1314aad4;hp=5e7969bb3a794e608fe4b3521c31223adcdd0176;hpb=b85b4d9e54caef0585d308ef3bffee21d0e5ae56;p=ardour.git diff --git a/gtk2_ardour/step_editor.cc b/gtk2_ardour/step_editor.cc index 5e7969bb3a..a65a7a8613 100644 --- a/gtk2_ardour/step_editor.cc +++ b/gtk2_ardour/step_editor.cc @@ -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" @@ -14,7 +33,7 @@ using namespace Gtk; using namespace std; StepEditor::StepEditor (PublicEditor& e, boost::shared_ptr t, MidiTimeAxisView& mtv) - : _editor (e) + : _editor (e) , _track (t) , step_editor (0) , _mtv (mtv) @@ -24,7 +43,7 @@ StepEditor::StepEditor (PublicEditor& e, boost::shared_ptr t, MidiTim _step_edit_within_chord = 0; _step_edit_chord_duration = 0.0; step_edit_region_view = 0; - + _track->PlaylistChanged.connect (*this, invalidator (*this), boost::bind (&StepEditor::playlist_changed, this), gui_context()); @@ -99,9 +118,9 @@ StepEditor::prepare_step_edit_region () const Meter& m = _mtv.session()->tempo_map().meter_at (step_edit_insert_position); const Tempo& t = _mtv.session()->tempo_map().tempo_at (step_edit_insert_position); - + step_edit_region = _mtv.add_region (step_edit_insert_position, floor (m.frames_per_bar (t, _mtv.session()->frame_rate())), true); - + RegionView* rv = _mtv.midi_view()->find_view (step_edit_region); step_edit_region_view = dynamic_cast(rv); } @@ -115,15 +134,15 @@ StepEditor::reset_step_edit_beat_pos () assert (step_edit_region_view); 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_beat_pos = step_edit_region_view->region_frames_to_region_beats (frames_from_start); step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos); } @@ -158,14 +177,14 @@ StepEditor::stop_step_editing () void StepEditor::check_step_edit () { - MidiRingBuffer& incoming (_track->step_edit_ring_buffer()); + MidiRingBuffer& incoming (_track->step_edit_ring_buffer()); uint8_t* buf; uint32_t bufsize = 32; buf = new uint8_t[bufsize]; while (incoming.read_space()) { - nframes_t time; + framepos_t time; Evoral::EventType type; uint32_t size; @@ -209,10 +228,10 @@ void StepEditor::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())); + step_edit_beat_pos = min (step_edit_beat_pos + beats, + step_edit_region_view->region_frames_to_region_beats (step_edit_region->length())); } else if (beats < 0.0) { - if (beats < step_edit_beat_pos) { + if (-beats < step_edit_beat_pos) { step_edit_beat_pos += beats; // its negative, remember } else { step_edit_beat_pos = 0; @@ -236,30 +255,29 @@ 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) { bool success; beat_duration = _editor.get_grid_type_as_beats (success, step_edit_insert_position); - + if (!success) { return -1; } } - + MidiStreamView* msv = _mtv.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 */ - - framepos_t fpos = step_edit_region->position() + - step_edit_region_view->beats_to_frames (step_edit_beat_pos + beat_duration); - + + 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)); } @@ -272,9 +290,9 @@ StepEditor::step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, Evo /* avoid any apparent note overlap - move the start of this note up by 1 tick from where the last note ended */ - - at += 1.0/Meter::ticks_per_beat; - len -= 1.0/Meter::ticks_per_beat; + + at += 1.0/Timecode::BBT_Time::ticks_per_beat; + len -= 1.0/Timecode::BBT_Time::ticks_per_beat; } step_edit_region_view->step_add_note (channel, pitch, velocity, at, len); @@ -284,17 +302,17 @@ StepEditor::step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, Evo 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_beat_pos += 1.0/Timecode::BBT_Time::ticks_per_beat; // tiny, but no longer overlapping _step_edit_chord_duration = max (_step_edit_chord_duration, beat_duration); } @@ -362,14 +380,14 @@ StepEditor::step_edit_rest (Evoral::MusicalTime beats) } } -void +void StepEditor::step_edit_beat_sync () { step_edit_beat_pos = ceil (step_edit_beat_pos); step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos); } -void +void StepEditor::step_edit_bar_sync () { Session* _session = _mtv.session (); @@ -378,10 +396,9 @@ StepEditor::step_edit_bar_sync () return; } - framepos_t fpos = step_edit_region->position() + - step_edit_region_view->beats_to_frames (step_edit_beat_pos); + 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->frames_to_beats (fpos - step_edit_region->position())); + step_edit_beat_pos = ceil (step_edit_region_view->region_frames_to_region_beats (fpos - step_edit_region->position())); step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos); } @@ -390,7 +407,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()); } @@ -398,7 +415,7 @@ void StepEditor::region_removed (boost::weak_ptr wr) { boost::shared_ptr r (wr.lock()); - + if (!r) { return; } @@ -412,7 +429,7 @@ StepEditor::region_removed (boost::weak_ptr wr) } string -StepEditor::name() const +StepEditor::name() const { return _track->name(); }