enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / editor_drag.cc
index bc640795fddfb49f2c47a067f5574c4ff948a283..a3b6664e57f4aeb5af57e62e6818861ef3dd4334 100644 (file)
@@ -44,7 +44,7 @@
 #include "canvas/scroll_group.h"
 
 #include "editor.h"
-#include "i18n.h"
+#include "pbd/i18n.h"
 #include "keyboard.h"
 #include "audio_region_view.h"
 #include "automation_region_view.h"
@@ -510,7 +510,7 @@ Drag::show_verbose_cursor_text (string const & text)
 }
 
 boost::shared_ptr<Region>
-Drag::add_midi_region (MidiTimeAxisView* view, bool commit)
+Drag::add_midi_region (MidiTimeAxisView* view, bool commit, const int32_t sub_num)
 {
        if (_editor->session()) {
                const TempoMap& map (_editor->session()->tempo_map());
@@ -519,18 +519,15 @@ Drag::add_midi_region (MidiTimeAxisView* view, bool commit)
                   might be wrong.
                */
                framecnt_t len = map.frame_at_beat (map.beat_at_frame (pos) + 1.0) - pos;
-               return view->add_region (grab_frame(), len, commit);
+               return view->add_region (grab_frame(), len, commit, sub_num);
        }
 
        return boost::shared_ptr<Region>();
 }
 
-struct EditorOrderTimeAxisViewSorter {
+struct PresentationInfoTimeAxisViewSorter {
        bool operator() (TimeAxisView* a, TimeAxisView* b) {
-               RouteTimeAxisView* ra = dynamic_cast<RouteTimeAxisView*> (a);
-               RouteTimeAxisView* rb = dynamic_cast<RouteTimeAxisView*> (b);
-               assert (ra && rb);
-               return ra->route()->order_key () < rb->route()->order_key ();
+               return a->stripable()->presentation_info().order() < b->stripable()->presentation_info().order();
        }
 };
 
@@ -546,7 +543,7 @@ RegionDrag::RegionDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<Re
        */
 
        TrackViewList track_views = _editor->track_views;
-       track_views.sort (EditorOrderTimeAxisViewSorter ());
+       track_views.sort (PresentationInfoTimeAxisViewSorter ());
 
        for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
                _time_axis_views.push_back (*i);
@@ -846,7 +843,7 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
 
                RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv);
                if (!rtv || !rtv->is_track()) {
-                       /* ignore busses early on. we can't move any regions on them */
+                       /* ignore non-tracks early on. we can't move any regions on them */
                } else if (_last_pointer_time_axis_view < 0) {
                        /* Was in the drop-zone, now over a track.
                         * Hence it must be an upward move (from the bottom)
@@ -1259,8 +1256,8 @@ RegionMoveDrag::motion (GdkEvent* event, bool first_move)
                        MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(rv);
 
                        const boost::shared_ptr<const Region> original = rv->region();
-                       boost::shared_ptr<Region> region_copy = RegionFactory::create (original, true);
-                       region_copy->set_position (original->position());
+                       boost::shared_ptr<Region> region_copy = RegionFactory::create (original, true
+                                                                                      , _editor->get_grid_music_divisions (event->button.state));
                        /* need to set this so that the drop zone code can work. This doesn't
                           actually put the region into the playlist, but just sets a weak pointer
                           to it.
@@ -1367,7 +1364,8 @@ RegionMoveDrag::finished (GdkEvent* ev, bool movement_occurred)
                finished_copy (
                        changed_position,
                        changed_tracks,
-                       drag_delta
+                       drag_delta,
+                       ev->button.state
                        );
 
        } else {
@@ -1375,7 +1373,8 @@ RegionMoveDrag::finished (GdkEvent* ev, bool movement_occurred)
                finished_no_copy (
                        changed_position,
                        changed_tracks,
-                       drag_delta
+                       drag_delta,
+                       ev->button.state
                        );
 
        }
@@ -1397,21 +1396,23 @@ RegionMoveDrag::create_destination_time_axis (boost::shared_ptr<Region> region,
                        if ((Config->get_output_auto_connect() & AutoConnectMaster) && _editor->session()->master_out()) {
                                output_chan =  _editor->session()->master_out()->n_inputs().n_audio();
                        }
-                       audio_tracks = _editor->session()->new_audio_track (region->n_channels(), output_chan, ARDOUR::Normal, 0, 1, region->name());
-                       RouteTimeAxisView* rtav = _editor->axis_view_from_route (audio_tracks.front());
-                       if (rtav) {
-                               rtav->set_height (original->current_height());
+                       audio_tracks = _editor->session()->new_audio_track (region->n_channels(), output_chan, 0, 1, region->name(), PresentationInfo::max_order);
+                       TimeAxisView* tav =_editor->axis_view_from_stripable (audio_tracks.front());
+                       if (tav) {
+                               tav->set_height (original->current_height());
                        }
-                       return rtav;
+                       return dynamic_cast<RouteTimeAxisView*>(tav);
                } else {
                        ChanCount one_midi_port (DataType::MIDI, 1);
                        list<boost::shared_ptr<MidiTrack> > midi_tracks;
-                       midi_tracks = _editor->session()->new_midi_track (one_midi_port, one_midi_port, boost::shared_ptr<ARDOUR::PluginInfo>(), ARDOUR::Normal, 0, 1, region->name());
-                       RouteTimeAxisView* rtav = _editor->axis_view_from_route (midi_tracks.front());
-                       if (rtav) {
-                               rtav->set_height (original->current_height());
+                       midi_tracks = _editor->session()->new_midi_track (one_midi_port, one_midi_port, boost::shared_ptr<ARDOUR::PluginInfo>(),
+                                                                         (ARDOUR::Plugin::PresetRecord*) 0,
+                                                                         (ARDOUR::RouteGroup*) 0, 1, region->name(), PresentationInfo::max_order);
+                       TimeAxisView* tav = _editor->axis_view_from_stripable (midi_tracks.front());
+                       if (tav) {
+                               tav->set_height (original->current_height());
                        }
-                       return rtav;
+                       return dynamic_cast<RouteTimeAxisView*> (tav);
                }
        } catch (...) {
                error << _("Could not create new track after region placed in the drop zone") << endmsg;
@@ -1420,7 +1421,7 @@ RegionMoveDrag::create_destination_time_axis (boost::shared_ptr<Region> region,
 }
 
 void
-RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed_tracks*/, framecnt_t const drag_delta)
+RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed_tracks*/, framecnt_t const drag_delta, int32_t const ev_state)
 {
        RegionSelection new_views;
        PlaylistSet modified_playlists;
@@ -1477,7 +1478,9 @@ RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed
                }
 
                if (dest_rtv != 0) {
-                       RegionView* new_view = insert_region_into_playlist (i->view->region(), dest_rtv, i->layer, where, modified_playlists);
+                       RegionView* new_view = insert_region_into_playlist (i->view->region(), dest_rtv, i->layer, where,
+                                                                           modified_playlists, _editor->get_grid_music_divisions (ev_state));
+
                        if (new_view != 0) {
                                new_views.push_back (new_view);
                        }
@@ -1511,7 +1514,8 @@ void
 RegionMoveDrag::finished_no_copy (
        bool const changed_position,
        bool const changed_tracks,
-       framecnt_t const drag_delta
+       framecnt_t const drag_delta,
+       int32_t const ev_state
        )
 {
        RegionSelection new_views;
@@ -1572,7 +1576,8 @@ RegionMoveDrag::finished_no_copy (
                        /* insert into new playlist */
 
                        RegionView* new_view = insert_region_into_playlist (
-                               RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, where, modified_playlists
+                               RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, where,
+                               modified_playlists, _editor->get_grid_music_divisions (ev_state)
                                );
 
                        if (new_view == 0) {
@@ -1632,7 +1637,7 @@ RegionMoveDrag::finished_no_copy (
                                playlist->freeze ();
                        }
 
-                       rv->region()->set_position (where);
+                       rv->region()->set_position (where, _editor->get_grid_music_divisions (ev_state));
                        _editor->session()->add_command (new StatefulDiffCommand (rv->region()));
                }
 
@@ -1735,7 +1740,8 @@ RegionMoveDrag::insert_region_into_playlist (
        RouteTimeAxisView* dest_rtv,
        layer_t dest_layer,
        framecnt_t where,
-       PlaylistSet& modified_playlists
+       PlaylistSet& modified_playlists,
+       const int32_t sub_num
        )
 {
        boost::shared_ptr<Playlist> dest_playlist = dest_rtv->playlist ();
@@ -1752,8 +1758,7 @@ RegionMoveDrag::insert_region_into_playlist (
        if (r.second) {
                dest_playlist->clear_changes ();
        }
-
-       dest_playlist->add_region (region, where);
+       dest_playlist->add_region (region, where, 1.0, false, sub_num);
 
        if (dest_rtv->view()->layer_display() == Stacked || dest_rtv->view()->layer_display() == Expanded) {
                dest_playlist->set_layer (region, dest_layer);
@@ -1877,7 +1882,7 @@ RegionInsertDrag::RegionInsertDrag (Editor* e, boost::shared_ptr<Region> r, Rout
 }
 
 void
-RegionInsertDrag::finished (GdkEvent *, bool)
+RegionInsertDrag::finished (GdkEvent * event, bool)
 {
        int pos = _views.front().time_axis_view;
        assert(pos >= 0 && pos < (int)_time_axis_views.size());
@@ -2304,7 +2309,7 @@ RegionCreateDrag::motion (GdkEvent* event, bool first_move)
 {
        if (first_move) {
                _editor->begin_reversible_command (_("create region"));
-               _region = add_midi_region (_view, false);
+               _region = add_midi_region (_view, false, _editor->get_grid_music_divisions (event->button.state));
                _view->playlist()->freeze ();
        } else {
                if (_region) {
@@ -2321,16 +2326,16 @@ RegionCreateDrag::motion (GdkEvent* event, bool first_move)
                        */
 
                        framecnt_t const len = (framecnt_t) fabs ((double)(f - grab_frame () - 1));
-                       _region->set_length (len < 1 ? 1 : len);
+                       _region->set_length (len < 1 ? 1 : len, _editor->get_grid_music_divisions (event->button.state));
                }
        }
 }
 
 void
-RegionCreateDrag::finished (GdkEvent*, bool movement_occurred)
+RegionCreateDrag::finished (GdkEvent* event, bool movement_occurred)
 {
        if (!movement_occurred) {
-               add_midi_region (_view, true);
+               add_midi_region (_view, true, _editor->get_grid_music_divisions (event->button.state));
        } else {
                _view->playlist()->thaw ();
                _editor->commit_reversible_command();
@@ -2912,7 +2917,9 @@ TrimDrag::motion (GdkEvent* event, bool first_move)
        switch (_operation) {
        case StartTrim:
                for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
-                       bool changed = i->view->trim_front (i->initial_position + dt, non_overlap_trim);
+                       bool changed = i->view->trim_front (i->initial_position + dt, non_overlap_trim
+                                                           , _editor->get_grid_music_divisions (event->button.state));
+
                        if (changed && _preserve_fade_anchor) {
                                AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
                                if (arv) {
@@ -2930,7 +2937,7 @@ TrimDrag::motion (GdkEvent* event, bool first_move)
 
        case EndTrim:
                for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
-                       bool changed = i->view->trim_end (i->initial_end + dt, non_overlap_trim);
+                       bool changed = i->view->trim_end (i->initial_end + dt, non_overlap_trim, _editor->get_grid_music_divisions (event->button.state));
                        if (changed && _preserve_fade_anchor) {
                                AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
                                if (arv) {
@@ -3182,6 +3189,10 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move)
                        const double beat = map.beat_at_bbt (bbt);
                        _real_section = map.add_meter (Meter (_marker->meter().divisions_per_bar(), _marker->meter().note_divisor())
                                                       , beat, bbt, map.frame_at_bbt (bbt), _real_section->position_lock_style());
+                       if (!_real_section) {
+                               aborted (true);
+                               return;
+                       }
 
                }
                /* only snap to bars. leave snap mode alone for audio locked meters.*/
@@ -3274,7 +3285,7 @@ TempoMarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
 void
 TempoMarkerDrag::setup_pointer_frame_offset ()
 {
-       _pointer_frame_offset = raw_grab_frame() - _marker->tempo().frame();
+       _pointer_frame_offset = raw_grab_frame() - _real_section->frame();
 }
 
 void
@@ -3313,14 +3324,21 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
                        _editor->begin_reversible_command (_("move tempo mark"));
 
                } else {
+                       const Tempo tempo (_marker->tempo());
                        const framepos_t frame = adjusted_current_frame (event) + 1;
+                       const TempoSection::Type type = _real_section->type();
 
                        _editor->begin_reversible_command (_("copy tempo mark"));
 
                        if (_real_section->position_lock_style() == MusicTime) {
-                               _real_section = map.add_tempo (_marker->tempo(), map.pulse_at_frame (frame), 0, _real_section->type(), MusicTime);
+                               _real_section = map.add_tempo (tempo, map.pulse_at_frame (frame), 0, type, MusicTime);
                        } else {
-                               _real_section = map.add_tempo (_marker->tempo(), 0.0, frame, _real_section->type(), AudioTime);
+                               _real_section = map.add_tempo (tempo, 0.0, frame, type, AudioTime);
+                       }
+
+                       if (!_real_section) {
+                               aborted (true);
+                               return;
                        }
                }
 
@@ -3336,42 +3354,16 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
                show_verbose_cursor_text (strs.str());
 
        } else if (_movable && !_real_section->locked_to_meter()) {
-               TempoMap& map (_editor->session()->tempo_map());
-               const bool was_music = _real_section->position_lock_style() == MusicTime;
-
                const framepos_t pf = adjusted_current_frame (event);
+               TempoMap& map (_editor->session()->tempo_map());
 
-               if (!_editor->snap_musical()) {
-
-                       if (was_music) {
-                               _real_section->set_position_lock_style (AudioTime);
-                       }
-
-                       map.gui_move_tempo (_real_section, pf);
-
-                       if (was_music) {
-                               _real_section->set_position_lock_style (MusicTime);
-                       }
-
-               } else {
-
-                       if (!was_music) {
-                               _real_section->set_position_lock_style (MusicTime);
-                       }
-
-                       map.gui_move_tempo (_real_section, pf);
+               /* snap to beat is 1, snap to bar is -1 (sorry) */
+               int sub_num = _editor->get_grid_music_divisions (event->button.state);
 
-                       if (!was_music) {
-                               _real_section->set_position_lock_style (AudioTime);
-                       }
-               }
+               map.gui_move_tempo (_real_section, pf, sub_num);
 
                show_verbose_cursor_time (_real_section->frame());
        }
-
-       /* this has moved the bar lines themselves, so recalibrate the offset */
-       setup_pointer_frame_offset();
-
        _marker->set_position (adjusted_current_frame (event, false));
 }
 
@@ -3406,8 +3398,7 @@ TempoMarkerDrag::aborted (bool moved)
        if (moved) {
                TempoMap& map (_editor->session()->tempo_map());
                map.set_state (*before_state, Stateful::current_state_version);
-               // delete the dummy marker we used for visual representation while moving.
-               // a new visual marker will show up automatically.
+               // delete the dummy (hidden) marker we used for events while moving.
                delete _marker;
        }
 }
@@ -3415,7 +3406,6 @@ TempoMarkerDrag::aborted (bool moved)
 BBTRulerDrag::BBTRulerDrag (Editor* e, ArdourCanvas::Item* i)
        : Drag (e, i)
        , _pulse (0.0)
-       , _beat (0.0)
        , _tempo (0)
        , before_state (0)
 {
@@ -3427,11 +3417,10 @@ void
 BBTRulerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
 {
        Drag::start_grab (event, cursor);
-
        TempoMap& map (_editor->session()->tempo_map());
+       _tempo = const_cast<TempoSection*> (&map.tempo_section_at_frame (raw_grab_frame()));
        ostringstream sstr;
 
-       _tempo = const_cast<TempoSection*> (&map.tempo_section_at_frame (raw_grab_frame()));
        sstr << "^" << fixed << setprecision(3) << map.tempo_at_frame (adjusted_current_frame (event)).beats_per_minute() << "\n";
        sstr << "<" << fixed << setprecision(3) << _tempo->beats_per_minute();
        show_verbose_cursor_text (sstr.str());
@@ -3444,17 +3433,22 @@ BBTRulerDrag::setup_pointer_frame_offset ()
        TempoMap& map (_editor->session()->tempo_map());
        const double beat_at_frame = map.beat_at_frame (raw_grab_frame());
        const uint32_t divisions = _editor->get_grid_beat_divisions (0);
+       double beat = 0.0;
+
        if (divisions > 0) {
-               _beat = floor (beat_at_frame) + (floor (((beat_at_frame - floor (beat_at_frame)) * divisions)) / divisions);
+               beat = floor (beat_at_frame) + (floor (((beat_at_frame - floor (beat_at_frame)) * divisions)) / divisions);
        } else {
                /* while it makes some sense for the user to determine the division to 'grab',
                   grabbing a bar often leads to confusing results wrt the actual tempo section being altered
                   and the result over steep tempo curves. Use sixteenths.
                */
-               _beat = floor (beat_at_frame) + (floor (((beat_at_frame - floor (beat_at_frame)) * 4)) / 4);
+               beat = floor (beat_at_frame) + (floor (((beat_at_frame - floor (beat_at_frame)) * 4)) / 4);
        }
-       _pulse = map.pulse_at_beat (_beat);
-       _pointer_frame_offset = raw_grab_frame() - map.frame_at_beat (_beat);
+
+       _pulse = map.pulse_at_beat (beat);
+
+       _pointer_frame_offset = raw_grab_frame() - map.frame_at_pulse (_pulse);
+
 }
 
 void
@@ -3468,7 +3462,13 @@ BBTRulerDrag::motion (GdkEvent* event, bool first_move)
                _editor->begin_reversible_command (_("dilate tempo"));
        }
 
-       framepos_t const pf = adjusted_current_frame (event);
+       framepos_t pf;
+
+       if (_editor->snap_musical()) {
+               pf = adjusted_current_frame (event, false);
+       } else {
+               pf = adjusted_current_frame (event);
+       }
 
        if (Keyboard::modifier_state_contains (event->button.state, ArdourKeyboard::constraint_modifier())) {
                /* adjust previous tempo to match pointer frame */
@@ -4244,6 +4244,10 @@ MarkerDrag::finished (GdkEvent* event, bool movement_occurred)
                        } else {
                                location->set (((*x).location)->start(), ((*x).location)->end());
                        }
+
+                       if (location->is_session_range()) {
+                               _editor->session()->set_end_is_free (false);
+                       }
                }
        }
 
@@ -4775,7 +4779,7 @@ RubberbandSelectDrag::finished (GdkEvent* event, bool movement_occurred)
                        /* MIDI track */
                        if (_editor->selection->empty() && _editor->mouse_mode == MouseDraw) {
                                /* nothing selected */
-                               add_midi_region (mtv, true);
+                               add_midi_region (mtv, true, _editor->get_grid_music_divisions(event->button.state));
                                do_deselect = false;
                        }
                }
@@ -5102,7 +5106,7 @@ SelectionDrag::motion (GdkEvent* event, bool first_move)
                        TrackViewList grouped_add = new_selection;
                        for (TrackViewList::const_iterator i = new_selection.begin(); i != new_selection.end(); ++i) {
                                RouteTimeAxisView *n = dynamic_cast<RouteTimeAxisView *>(*i);
-                               if ( n && n->route()->route_group() && n->route()->route_group()->is_active() && n->route()->route_group()->enabled_property (ARDOUR::Properties::select.property_id) ) {
+                               if ( n && n->route()->route_group() && n->route()->route_group()->is_active() && n->route()->route_group()->enabled_property (ARDOUR::Properties::group_select.property_id) ) {
                                        for (TrackViewList::const_iterator j = all_tracks.begin(); j != all_tracks.end(); ++j) {
                                                RouteTimeAxisView *check = dynamic_cast<RouteTimeAxisView *>(*j);
                                                if ( check && (n != check) && (check->route()->route_group() == n->route()->route_group()) )
@@ -6010,6 +6014,9 @@ void
 PatchChangeDrag::finished (GdkEvent* ev, bool movement_occurred)
 {
        if (!movement_occurred) {
+               if (was_double_click()) {
+                       _region_view->edit_patch_change (_patch_change);
+               }
                return;
        }
 
@@ -6344,7 +6351,7 @@ RegionCutDrag::motion (GdkEvent*, bool)
 }
 
 void
-RegionCutDrag::finished (GdkEvent*, bool)
+RegionCutDrag::finished (GdkEvent* event, bool)
 {
        _editor->get_track_canvas()->canvas()->re_enter();
 
@@ -6358,7 +6365,7 @@ RegionCutDrag::finished (GdkEvent*, bool)
                return;
        }
 
-       _editor->split_regions_at (pos, rs);
+       _editor->split_regions_at (pos, rs, _editor->get_grid_music_divisions (event->button.state));
 }
 
 void