- show_verbose_time_cursor (cursor->current_frame, 10);
-
- drag_info.last_pointer_frame = adjusted_frame;
- drag_info.first_move = false;
-}
-
-void
-Editor::cursor_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
-{
- if (drag_info.first_move) return;
-
- cursor_drag_motion_callback (item, event);
-
- _dragging_playhead = false;
-
- if (item == &playhead_cursor->canvas_item) {
- if (session) {
- session->request_locate (playhead_cursor->current_frame, drag_info.was_rolling);
- }
- } else if (item == &edit_cursor->canvas_item) {
- edit_cursor->set_position (edit_cursor->current_frame);
- edit_cursor_clock.set (edit_cursor->current_frame);
- }
-}
-
-void
-Editor::update_marker_drag_item (Location *location)
-{
- double x1 = frame_to_pixel (location->start());
- double x2 = frame_to_pixel (location->end());
-
- if (location->is_mark()) {
- marker_drag_line_points.front().set_x(x1);
- marker_drag_line_points.back().set_x(x1);
- marker_drag_line->property_points() = marker_drag_line_points;
- }
- else {
- range_marker_drag_rect->property_x1() = x1;
- range_marker_drag_rect->property_x2() = x2;
- }
-}
-
-void
-Editor::start_marker_grab (ArdourCanvas::Item* item, GdkEvent* event)
-{
- Marker* marker;
-
- if ((marker = static_cast<Marker *> (item->get_data ("marker"))) == 0) {
- fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
- /*NOTREACHED*/
- }
-
- bool is_start;
-
- Location *location = find_location_from_marker (marker, is_start);
-
- drag_info.item = item;
- drag_info.data = marker;
- drag_info.motion_callback = &Editor::marker_drag_motion_callback;
- drag_info.finished_callback = &Editor::marker_drag_finished_callback;
-
- start_grab (event);
-
- drag_info.copied_location = new Location (*location);
- drag_info.pointer_frame_offset = drag_info.grab_frame - (is_start ? location->start() : location->end());
-
- update_marker_drag_item (location);
-
- if (location->is_mark()) {
- marker_drag_line->show();
- marker_drag_line->raise_to_top();
- } else {
- range_marker_drag_rect->show();
- range_marker_drag_rect->raise_to_top();
- }
-
- if (is_start) {
- show_verbose_time_cursor (location->start(), 10);
- } else {
- show_verbose_time_cursor (location->end(), 10);
- }
-}
-
-void
-Editor::marker_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
-{
- nframes_t f_delta;
- Marker* marker = (Marker *) drag_info.data;
- Location *real_location;
- Location *copy_location;
- bool is_start;
- bool move_both = false;
-
-
- nframes_t newframe;
- if (drag_info.pointer_frame_offset <= drag_info.current_pointer_frame) {
- newframe = drag_info.current_pointer_frame - drag_info.pointer_frame_offset;
- } else {
- newframe = 0;
- }
-
- nframes_t next = newframe;
-
- if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
- snap_to (newframe, 0, true);
- }
-
- if (drag_info.current_pointer_frame == drag_info.last_pointer_frame) {
- return;
- }
-
- /* call this to find out if its the start or end */
-
- real_location = find_location_from_marker (marker, is_start);
-
- /* use the copy that we're "dragging" around */
-
- copy_location = drag_info.copied_location;
-
- f_delta = copy_location->end() - copy_location->start();
-
- if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) {
- move_both = true;
- }
-
- if (copy_location->is_mark()) {
- /* just move it */
-
- copy_location->set_start (newframe);
-
- } else {
-
- if (is_start) { // start-of-range marker
-
- if (move_both) {
- copy_location->set_start (newframe);
- copy_location->set_end (newframe + f_delta);
- } else if (newframe < copy_location->end()) {
- copy_location->set_start (newframe);
- } else {
- snap_to (next, 1, true);
- copy_location->set_end (next);
- copy_location->set_start (newframe);
- }
-
- } else { // end marker
-
- if (move_both) {
- copy_location->set_end (newframe);
- copy_location->set_start (newframe - f_delta);
- } else if (newframe > copy_location->start()) {
- copy_location->set_end (newframe);
-
- } else if (newframe > 0) {
- snap_to (next, -1, true);
- copy_location->set_start (next);
- copy_location->set_end (newframe);
- }
- }
- }
-
- drag_info.last_pointer_frame = drag_info.current_pointer_frame;
- drag_info.first_move = false;
-
- update_marker_drag_item (copy_location);
-
- LocationMarkers* lm = find_location_markers (real_location);
- lm->set_position (copy_location->start(), copy_location->end());
-
- show_verbose_time_cursor (newframe, 10);
-}
-
-void
-Editor::marker_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
-{
- if (drag_info.first_move) {
- marker_drag_motion_callback (item, event);
-
- }
-
- Marker* marker = (Marker *) drag_info.data;
- bool is_start;
-
-
- begin_reversible_command ( _("move marker") );
- XMLNode &before = session->locations()->get_state();
-
- Location * location = find_location_from_marker (marker, is_start);
-
- if (location) {
- if (location->is_mark()) {
- location->set_start (drag_info.copied_location->start());
- } else {
- location->set (drag_info.copied_location->start(), drag_info.copied_location->end());
- }
- }
-
- XMLNode &after = session->locations()->get_state();
- session->add_command(new MementoCommand<Locations>(*(session->locations()), &before, &after));
- commit_reversible_command ();
-
- marker_drag_line->hide();
- range_marker_drag_rect->hide();
-}
-
-void
-Editor::start_meter_marker_grab (ArdourCanvas::Item* item, GdkEvent* event)
-{
- Marker* marker;
- MeterMarker* meter_marker;
-
- if ((marker = reinterpret_cast<Marker *> (item->get_data ("marker"))) == 0) {
- fatal << _("programming error: meter marker canvas item has no marker object pointer!") << endmsg;
- /*NOTREACHED*/
- }
-
- meter_marker = dynamic_cast<MeterMarker*> (marker);
-
- MetricSection& section (meter_marker->meter());
-
- if (!section.movable()) {
- return;
- }
-
- drag_info.item = item;
- drag_info.data = marker;
- drag_info.motion_callback = &Editor::meter_marker_drag_motion_callback;
- drag_info.finished_callback = &Editor::meter_marker_drag_finished_callback;
-
- start_grab (event);
-
- drag_info.pointer_frame_offset = drag_info.grab_frame - meter_marker->meter().frame();
-
- show_verbose_time_cursor (drag_info.current_pointer_frame, 10);
-}
-
-void
-Editor::start_meter_marker_copy_grab (ArdourCanvas::Item* item, GdkEvent* event)
-{
- Marker* marker;
- MeterMarker* meter_marker;
-
- if ((marker = reinterpret_cast<Marker *> (item->get_data ("marker"))) == 0) {
- fatal << _("programming error: meter marker canvas item has no marker object pointer!") << endmsg;
- /*NOTREACHED*/
- }
-
- meter_marker = dynamic_cast<MeterMarker*> (marker);
-
- // create a dummy marker for visual representation of moving the copy.
- // The actual copying is not done before we reach the finish callback.
- char name[64];
- snprintf (name, sizeof(name), "%g/%g", meter_marker->meter().beats_per_bar(), meter_marker->meter().note_divisor ());
- MeterMarker* new_marker = new MeterMarker(*this, *meter_group, ARDOUR_UI::config()->canvasvar_MeterMarker.get(), name,
- *new MeterSection(meter_marker->meter()));
-
- drag_info.item = &new_marker->the_item();
- drag_info.copy = true;
- drag_info.data = new_marker;
- drag_info.motion_callback = &Editor::meter_marker_drag_motion_callback;
- drag_info.finished_callback = &Editor::meter_marker_drag_finished_callback;
-
- start_grab (event);
-
- drag_info.pointer_frame_offset = drag_info.grab_frame - meter_marker->meter().frame();
-
- show_verbose_time_cursor (drag_info.current_pointer_frame, 10);
-}
-
-void
-Editor::meter_marker_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
-{
- MeterMarker* marker = (MeterMarker *) drag_info.data;
- nframes_t adjusted_frame;
-
- if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
- adjusted_frame = drag_info.current_pointer_frame - drag_info.pointer_frame_offset;
- }
- else {
- adjusted_frame = 0;
- }
-
- if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
- snap_to (adjusted_frame);
- }
-
- if (adjusted_frame == drag_info.last_pointer_frame) return;
-
- marker->set_position (adjusted_frame);
-
-
- drag_info.last_pointer_frame = adjusted_frame;
- drag_info.first_move = false;
-
- show_verbose_time_cursor (adjusted_frame, 10);
-}
-
-void
-Editor::meter_marker_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
-{
- if (drag_info.first_move) return;
-
- meter_marker_drag_motion_callback (drag_info.item, event);
-
- MeterMarker* marker = (MeterMarker *) drag_info.data;
- BBT_Time when;
-
- TempoMap& map (session->tempo_map());
- map.bbt_time (drag_info.last_pointer_frame, when);
-
- if (drag_info.copy == true) {
- begin_reversible_command (_("copy meter mark"));
- XMLNode &before = map.get_state();
- map.add_meter (marker->meter(), when);
- XMLNode &after = map.get_state();
- session->add_command(new MementoCommand<TempoMap>(map, &before, &after));
- commit_reversible_command ();
-
- // delete the dummy marker we used for visual representation of copying.
- // a new visual marker will show up automatically.
- delete marker;
- } else {
- begin_reversible_command (_("move meter mark"));
- XMLNode &before = map.get_state();
- map.move_meter (marker->meter(), when);
- XMLNode &after = map.get_state();
- session->add_command(new MementoCommand<TempoMap>(map, &before, &after));
- commit_reversible_command ();
- }
-}
-
-void
-Editor::start_tempo_marker_grab (ArdourCanvas::Item* item, GdkEvent* event)
-{
- Marker* marker;
- TempoMarker* tempo_marker;
-
- if ((marker = reinterpret_cast<Marker *> (item->get_data ("marker"))) == 0) {
- fatal << _("programming error: tempo marker canvas item has no marker object pointer!") << endmsg;
- /*NOTREACHED*/
- }
-
- if ((tempo_marker = dynamic_cast<TempoMarker *> (marker)) == 0) {
- fatal << _("programming error: marker for tempo is not a tempo marker!") << endmsg;
- /*NOTREACHED*/
- }
-
- MetricSection& section (tempo_marker->tempo());
-
- if (!section.movable()) {
- return;
- }
-
- drag_info.item = item;
- drag_info.data = marker;
- drag_info.motion_callback = &Editor::tempo_marker_drag_motion_callback;
- drag_info.finished_callback = &Editor::tempo_marker_drag_finished_callback;
-
- start_grab (event);
-
- drag_info.pointer_frame_offset = drag_info.grab_frame - tempo_marker->tempo().frame();
- show_verbose_time_cursor (drag_info.current_pointer_frame, 10);
-}
-
-void
-Editor::start_tempo_marker_copy_grab (ArdourCanvas::Item* item, GdkEvent* event)
-{
- Marker* marker;
- TempoMarker* tempo_marker;
-
- if ((marker = reinterpret_cast<Marker *> (item->get_data ("marker"))) == 0) {
- fatal << _("programming error: tempo marker canvas item has no marker object pointer!") << endmsg;
- /*NOTREACHED*/
- }
-
- if ((tempo_marker = dynamic_cast<TempoMarker *> (marker)) == 0) {
- fatal << _("programming error: marker for tempo is not a tempo marker!") << endmsg;
- /*NOTREACHED*/
- }
-
- // create a dummy marker for visual representation of moving the copy.
- // The actual copying is not done before we reach the finish callback.
- char name[64];
- snprintf (name, sizeof (name), "%.2f", tempo_marker->tempo().beats_per_minute());
- TempoMarker* new_marker = new TempoMarker(*this, *tempo_group, ARDOUR_UI::config()->canvasvar_TempoMarker.get(), name,
- *new TempoSection(tempo_marker->tempo()));
-
- drag_info.item = &new_marker->the_item();
- drag_info.copy = true;
- drag_info.data = new_marker;
- drag_info.motion_callback = &Editor::tempo_marker_drag_motion_callback;
- drag_info.finished_callback = &Editor::tempo_marker_drag_finished_callback;
-
- start_grab (event);
-
- drag_info.pointer_frame_offset = drag_info.grab_frame - tempo_marker->tempo().frame();
-
- show_verbose_time_cursor (drag_info.current_pointer_frame, 10);
-}
-
-void
-Editor::tempo_marker_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
-{
- TempoMarker* marker = (TempoMarker *) drag_info.data;
- nframes_t adjusted_frame;
-
- if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
- adjusted_frame = drag_info.current_pointer_frame - drag_info.pointer_frame_offset;
- }
- else {
- adjusted_frame = 0;
- }
-
- if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
- snap_to (adjusted_frame);
- }
-
- if (adjusted_frame == drag_info.last_pointer_frame) return;
-
- /* OK, we've moved far enough to make it worth actually move the thing. */
-
- marker->set_position (adjusted_frame);
-
- show_verbose_time_cursor (adjusted_frame, 10);
-
- drag_info.last_pointer_frame = adjusted_frame;
- drag_info.first_move = false;
-}
-
-void
-Editor::tempo_marker_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
-{
- if (drag_info.first_move) return;
-
- tempo_marker_drag_motion_callback (drag_info.item, event);
-
- TempoMarker* marker = (TempoMarker *) drag_info.data;
- BBT_Time when;
-
- TempoMap& map (session->tempo_map());
- map.bbt_time (drag_info.last_pointer_frame, when);
-
- if (drag_info.copy == true) {
- begin_reversible_command (_("copy tempo mark"));
- XMLNode &before = map.get_state();
- map.add_tempo (marker->tempo(), when);
- XMLNode &after = map.get_state();
- session->add_command (new MementoCommand<TempoMap>(map, &before, &after));
- commit_reversible_command ();
-
- // delete the dummy marker we used for visual representation of copying.
- // a new visual marker will show up automatically.
- delete marker;
- } else {
- begin_reversible_command (_("move tempo mark"));
- XMLNode &before = map.get_state();
- map.move_tempo (marker->tempo(), when);
- XMLNode &after = map.get_state();
- session->add_command (new MementoCommand<TempoMap>(map, &before, &after));
- commit_reversible_command ();
- }
-}
-
-void
-Editor::remove_gain_control_point (ArdourCanvas::Item*item, GdkEvent* event)
-{
- ControlPoint* control_point;
-
- if ((control_point = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"))) == 0) {
- fatal << _("programming error: control point canvas item has no control point object pointer!") << endmsg;
- /*NOTREACHED*/
- }
-
- // We shouldn't remove the first or last gain point
- if (control_point->line().is_last_point(*control_point) ||
- control_point->line().is_first_point(*control_point)) {
- return;
- }
-
- control_point->line().remove_point (*control_point);
-}
-
-void
-Editor::remove_control_point (ArdourCanvas::Item* item, GdkEvent* event)
-{
- ControlPoint* control_point;
-
- if ((control_point = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"))) == 0) {
- fatal << _("programming error: control point canvas item has no control point object pointer!") << endmsg;
- /*NOTREACHED*/
- }
-
- control_point->line().remove_point (*control_point);
-}
-
-void
-Editor::start_control_point_grab (ArdourCanvas::Item* item, GdkEvent* event)
-{
- ControlPoint* control_point;
-
- if ((control_point = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"))) == 0) {
- fatal << _("programming error: control point canvas item has no control point object pointer!") << endmsg;
- /*NOTREACHED*/
- }
-
- drag_info.item = item;
- drag_info.data = control_point;
- drag_info.motion_callback = &Editor::control_point_drag_motion_callback;
- drag_info.finished_callback = &Editor::control_point_drag_finished_callback;
-
- start_grab (event, fader_cursor);
-
- // start the grab at the center of the control point so
- // the point doesn't 'jump' to the mouse after the first drag
- drag_info.grab_x = control_point->get_x();
- drag_info.grab_y = control_point->get_y();
- control_point->line().parent_group().i2w(drag_info.grab_x, drag_info.grab_y);
- track_canvas.w2c(drag_info.grab_x, drag_info.grab_y,
- drag_info.grab_x, drag_info.grab_y);
-
- drag_info.grab_frame = pixel_to_frame(drag_info.grab_x);
-
- control_point->line().start_drag (control_point, drag_info.grab_frame, 0);
-
- double fraction = 1.0 - ((control_point->get_y() - control_point->line().y_position()) / (double)control_point->line().height());
- set_verbose_canvas_cursor (control_point->line().get_verbose_cursor_string (fraction),
- drag_info.current_pointer_x + 20, drag_info.current_pointer_y + 20);
-
- show_verbose_canvas_cursor ();
-}
-
-void
-Editor::control_point_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
-{
- ControlPoint* cp = reinterpret_cast<ControlPoint *> (drag_info.data);
-
- double dx = drag_info.current_pointer_x - drag_info.last_pointer_x;
- double dy = drag_info.current_pointer_y - drag_info.last_pointer_y;
-
- if (event->button.state & Keyboard::Alt) {
- dx *= 0.1;
- dy *= 0.1;
- }
-
- double cx = drag_info.grab_x + drag_info.cumulative_x_drag + dx;
- double cy = drag_info.grab_y + drag_info.cumulative_y_drag + dy;
-
- // calculate zero crossing point. back off by .01 to stay on the
- // positive side of zero
- double _unused = 0;
- double zero_gain_y = (1.0 - ZERO_GAIN_FRACTION) * cp->line().height() - .01;
- cp->line().parent_group().i2w(_unused, zero_gain_y);
-
- // make sure we hit zero when passing through
- if ((cy < zero_gain_y and (cy - dy) > zero_gain_y)
- or (cy > zero_gain_y and (cy - dy) < zero_gain_y)) {
- cy = zero_gain_y;
- }
-
- if (drag_info.x_constrained) {
- cx = drag_info.grab_x;
- }
- if (drag_info.y_constrained) {
- cy = drag_info.grab_y;
- }
-
- drag_info.cumulative_x_drag = cx - drag_info.grab_x;
- drag_info.cumulative_y_drag = cy - drag_info.grab_y;
-
- cp->line().parent_group().w2i (cx, cy);
-
- cx = max (0.0, cx);
- cy = max (0.0, cy);
- cy = min ((double) (cp->line().y_position() + cp->line().height()), cy);
-
- //translate cx to frames
- nframes_t cx_frames = unit_to_frame (cx);
-
- if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier()) && !drag_info.x_constrained) {
- snap_to (cx_frames);
- }
-
- const double fraction = 1.0 - ((cy - cp->line().y_position()) / (double)cp->line().height());
-
- bool push;
-
- if (Keyboard::modifier_state_contains (event->button.state, Keyboard::Control)) {
- push = true;
- } else {
- push = false;
- }
-
- cp->line().point_drag (*cp, cx_frames , fraction, push);
-
- set_verbose_canvas_cursor_text (cp->line().get_verbose_cursor_string (fraction));
-
- drag_info.first_move = false;
-}
-
-void
-Editor::control_point_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
-{
- ControlPoint* cp = reinterpret_cast<ControlPoint *> (drag_info.data);
-
- if (drag_info.first_move) {
-
- /* just a click */
-
- if ((event->type == GDK_BUTTON_RELEASE) && (event->button.button == 1) && Keyboard::modifier_state_equals (event->button.state, Keyboard::Shift)) {
- reset_point_selection ();
- }
-
- } else {
- control_point_drag_motion_callback (item, event);
- }
- cp->line().end_drag (cp);
-}
-
-void
-Editor::start_line_grab_from_regionview (ArdourCanvas::Item* item, GdkEvent* event)
-{
- switch (mouse_mode) {
- case MouseGain:
- assert(dynamic_cast<AudioRegionView*>(clicked_regionview));
- start_line_grab (dynamic_cast<AudioRegionView*>(clicked_regionview)->get_gain_line(), event);
- break;
- default:
- break;
- }
-}
-
-void
-Editor::start_line_grab_from_line (ArdourCanvas::Item* item, GdkEvent* event)
-{
- AutomationLine* al;
-
- if ((al = reinterpret_cast<AutomationLine*> (item->get_data ("line"))) == 0) {
- fatal << _("programming error: line canvas item has no line pointer!") << endmsg;
- /*NOTREACHED*/
- }
-
- start_line_grab (al, event);
-}
-
-void
-Editor::start_line_grab (AutomationLine* line, GdkEvent* event)
-{
- double cx;
- double cy;
- nframes_t frame_within_region;
-
- /* need to get x coordinate in terms of parent (TimeAxisItemView)
- origin.
- */
-
- cx = event->button.x;
- cy = event->button.y;
- line->parent_group().w2i (cx, cy);
- frame_within_region = (nframes_t) floor (cx * frames_per_unit);
-
- if (!line->control_points_adjacent (frame_within_region, current_line_drag_info.before,
- current_line_drag_info.after)) {
- /* no adjacent points */
- return;
- }
-
- drag_info.item = &line->grab_item();
- drag_info.data = line;
- drag_info.motion_callback = &Editor::line_drag_motion_callback;
- drag_info.finished_callback = &Editor::line_drag_finished_callback;
-
- start_grab (event, fader_cursor);
-
- const double fraction = 1.0 - ((cy - line->y_position()) / (double)line->height());
-
- line->start_drag (0, drag_info.grab_frame, fraction);
-
- set_verbose_canvas_cursor (line->get_verbose_cursor_string (fraction),
- drag_info.current_pointer_x + 20, drag_info.current_pointer_y + 20);
- show_verbose_canvas_cursor ();
-}
-
-void
-Editor::line_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
-{
- AutomationLine* line = reinterpret_cast<AutomationLine *> (drag_info.data);
-
- double dy = drag_info.current_pointer_y - drag_info.last_pointer_y;
-
- if (event->button.state & Keyboard::Alt) {
- dy *= 0.1;
- }
-
- double cx = drag_info.current_pointer_x;
- double cy = drag_info.grab_y + drag_info.cumulative_y_drag + dy;
-
- // calculate zero crossing point. back off by .01 to stay on the
- // positive side of zero
- double _unused = 0;
- double zero_gain_y = (1.0 - ZERO_GAIN_FRACTION) * line->height() - .01;
- line->parent_group().i2w(_unused, zero_gain_y);
-
- // make sure we hit zero when passing through
- if ((cy < zero_gain_y and (cy - dy) > zero_gain_y)
- or (cy > zero_gain_y and (cy - dy) < zero_gain_y)) {
- cy = zero_gain_y;
- }
-
- drag_info.cumulative_y_drag = cy - drag_info.grab_y;
-
- line->parent_group().w2i (cx, cy);
-
- cy = max (0.0, cy);
- cy = min ((double) line->height(), cy);
-
- const double fraction = 1.0 - ((cy - line->y_position()) / (double)line->height());
-
- bool push;
-
- if (Keyboard::modifier_state_contains (event->button.state, Keyboard::Control)) {
- push = false;
- } else {
- push = true;
- }
-
- line->line_drag (current_line_drag_info.before, current_line_drag_info.after, fraction, push);
-
- set_verbose_canvas_cursor_text (line->get_verbose_cursor_string (fraction));
-}
-
-void
-Editor::line_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
-{
- AutomationLine* line = reinterpret_cast<AutomationLine *> (drag_info.data);
- line_drag_motion_callback (item, event);
- line->end_drag (0);
-}
-
-void
-Editor::start_region_grab (ArdourCanvas::Item* item, GdkEvent* event)
-{
- if (selection->regions.empty() || clicked_regionview == 0) {
- return;
- }
-
- drag_info.copy = false;
- drag_info.item = item;
- drag_info.data = clicked_regionview;
- drag_info.motion_callback = &Editor::region_drag_motion_callback;
- drag_info.finished_callback = &Editor::region_drag_finished_callback;
-
- start_grab (event);
-
- double speed = 1.0;
- TimeAxisView* tvp = clicked_axisview;
- RouteTimeAxisView* tv = dynamic_cast<RouteTimeAxisView*>(tvp);
-
- if (tv && tv->is_track()) {
- speed = tv->get_diskstream()->speed();
- }
-
- drag_info.last_frame_position = (nframes_t) (clicked_regionview->region()->position() / speed);
- drag_info.pointer_frame_offset = drag_info.grab_frame - drag_info.last_frame_position;
- drag_info.last_trackview = &clicked_regionview->get_time_axis_view();
- // we want a move threshold
- drag_info.want_move_threshold = true;
-
- show_verbose_time_cursor (drag_info.last_frame_position, 10);
-
- begin_reversible_command (_("move region(s)"));
-}
-
-void
-Editor::start_create_region_grab (ArdourCanvas::Item* item, GdkEvent* event)
-{
- drag_info.copy = false;
- drag_info.item = item;
- drag_info.data = clicked_axisview;
- drag_info.last_trackview = clicked_axisview;
- drag_info.motion_callback = &Editor::create_region_drag_motion_callback;
- drag_info.finished_callback = &Editor::create_region_drag_finished_callback;
-
- start_grab (event);
-}
-
-void
-Editor::start_region_copy_grab (ArdourCanvas::Item* item, GdkEvent* event)
-{
- if (selection->regions.empty() || clicked_regionview == 0) {
- return;
- }
-
- drag_info.copy = true;
- drag_info.item = item;
- drag_info.data = clicked_regionview;
-
- start_grab(event);
-
- TimeAxisView* tv = &clicked_regionview->get_time_axis_view();
- RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(tv);
- double speed = 1.0;
-
- if (rtv && rtv->is_track()) {
- speed = rtv->get_diskstream()->speed();
- }
-
- drag_info.last_trackview = &clicked_regionview->get_time_axis_view();
- drag_info.last_frame_position = (nframes_t) (clicked_regionview->region()->position() / speed);
- drag_info.pointer_frame_offset = drag_info.grab_frame - drag_info.last_frame_position;
- // we want a move threshold
- drag_info.want_move_threshold = true;
- drag_info.motion_callback = &Editor::region_drag_motion_callback;
- drag_info.finished_callback = &Editor::region_drag_finished_callback;
- show_verbose_time_cursor (drag_info.last_frame_position, 10);
-}
-
-void
-Editor::start_region_brush_grab (ArdourCanvas::Item* item, GdkEvent* event)
-{
- if (selection->regions.empty() || clicked_regionview == 0) {
- return;
- }
-
- drag_info.copy = false;
- drag_info.item = item;
- drag_info.data = clicked_regionview;
- drag_info.motion_callback = &Editor::region_drag_motion_callback;
- drag_info.finished_callback = &Editor::region_drag_finished_callback;
-
- start_grab (event);
-
- double speed = 1.0;
- TimeAxisView* tvp = clicked_axisview;
- RouteTimeAxisView* tv = dynamic_cast<RouteTimeAxisView*>(tvp);
-
- if (tv && tv->is_track()) {
- speed = tv->get_diskstream()->speed();
- }
-
- drag_info.last_frame_position = (nframes_t) (clicked_regionview->region()->position() / speed);
- drag_info.pointer_frame_offset = drag_info.grab_frame - drag_info.last_frame_position;
- drag_info.last_trackview = &clicked_regionview->get_time_axis_view();
- // we want a move threshold
- drag_info.want_move_threshold = true;
- drag_info.brushing = true;
-
- begin_reversible_command (_("Drag region brush"));
-}
-
-void
-Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
-{
- double x_delta;
- double y_delta = 0;
- RegionView* rv = reinterpret_cast<RegionView*> (drag_info.data);
- nframes_t pending_region_position = 0;
- int32_t pointer_y_span = 0, canvas_pointer_y_span = 0, original_pointer_order;
- int32_t visible_y_high = 0, visible_y_low = 512; //high meaning higher numbered.. not the height on the screen
- bool clamp_y_axis = false;
- vector<int32_t> height_list(512) ;
- vector<int32_t>::iterator j;
-
- if (drag_info.copy && drag_info.move_threshold_passed && drag_info.want_move_threshold) {
-
- drag_info.want_move_threshold = false; // don't copy again
-
- /* duplicate the region(s) */
-
- vector<RegionView*> new_regionviews;
-
- for (list<RegionView*>::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) {
-
- RegionView* rv;
- RegionView* nrv;
-
- rv = (*i);
-
- AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
- MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(rv);
-
- if (arv) {
- nrv = new AudioRegionView (*arv);
- } else if (mrv) {
- nrv = new MidiRegionView (*mrv);
- } else {
- continue;
- }
-
- nrv->get_canvas_group()->show ();
-
- new_regionviews.push_back (nrv);
- }
-
- if (new_regionviews.empty()) {
- return;
- }
-
- /* reset selection to new regionviews */
-
- selection->set (new_regionviews);
-
- /* reset drag_info data to reflect the fact that we are dragging the copies */
-
- drag_info.data = new_regionviews.front();
-
- swap_grab (new_regionviews.front()->get_canvas_group (), 0, event->motion.time);
- }
-
- /* Which trackview is this ? */
-
- TimeAxisView* tvp = trackview_by_y_position (drag_info.current_pointer_y);
- RouteTimeAxisView* tv = dynamic_cast<RouteTimeAxisView*>(tvp);
-
- /* The region motion is only processed if the pointer is over
- an audio track.
- */
-
- if (!tv || !tv->is_track()) {
- /* To make sure we hide the verbose canvas cursor when the mouse is
- not held over a track.
- */
- hide_verbose_canvas_cursor ();
- return;
- }
-
- original_pointer_order = drag_info.last_trackview->order;
-
- /************************************************************
- Y-Delta Computation
- ************************************************************/
-
- if (drag_info.brushing) {
- clamp_y_axis = true;
- pointer_y_span = 0;
- goto y_axis_done;
- }
-
- if ((pointer_y_span = (drag_info.last_trackview->order - tv->order)) != 0) {
-
- int32_t children = 0, numtracks = 0;
- // XXX hard coding track limit, oh my, so very very bad
- bitset <1024> tracks (0x00);
- /* get a bitmask representing the visible tracks */
-
- for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
- TimeAxisView *tracklist_timeview;
- tracklist_timeview = (*i);
- RouteTimeAxisView* rtv2 = dynamic_cast<RouteTimeAxisView*>(tracklist_timeview);
- TimeAxisView::Children children_list;
-
- /* zeroes are audio tracks. ones are other types. */
-
- if (!rtv2->hidden()) {
-
- if (visible_y_high < rtv2->order) {
- visible_y_high = rtv2->order;
- }
- if (visible_y_low > rtv2->order) {
- visible_y_low = rtv2->order;
- }
-
- if (!rtv2->is_track()) {
- tracks = tracks |= (0x01 << rtv2->order);
- }
-
- height_list[rtv2->order] = (*i)->height;
- children = 1;
- if ((children_list = rtv2->get_child_list()).size() > 0) {
- for (TimeAxisView::Children::iterator j = children_list.begin(); j != children_list.end(); ++j) {
- tracks = tracks |= (0x01 << (rtv2->order + children));
- height_list[rtv2->order + children] = (*j)->height;
- numtracks++;
- children++;
- }
- }
- numtracks++;
- }
- }
- /* find the actual span according to the canvas */
-
- canvas_pointer_y_span = pointer_y_span;
- if (drag_info.last_trackview->order >= tv->order) {
- int32_t y;
- for (y = tv->order; y < drag_info.last_trackview->order; y++) {
- if (height_list[y] == 0 ) {
- canvas_pointer_y_span--;
- }
- }
- } else {
- int32_t y;
- for (y = drag_info.last_trackview->order;y <= tv->order; y++) {
- if ( height_list[y] == 0 ) {
- canvas_pointer_y_span++;
- }
- }
- }
-
- for (list<RegionView*>::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) {
- RegionView* rv2 = (*i);
- double ix1, ix2, iy1, iy2;
- int32_t n = 0;
-
- rv2->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2);
- rv2->get_canvas_group()->i2w (ix1, iy1);
- TimeAxisView* tvp2 = trackview_by_y_position (iy1);
- RouteTimeAxisView* rtv2 = dynamic_cast<RouteTimeAxisView*>(tvp2);
-
- if (rtv2->order != original_pointer_order) {
- /* this isn't the pointer track */
-
- if (canvas_pointer_y_span > 0) {
-
- /* moving up the canvas */
- if ((rtv2->order - canvas_pointer_y_span) >= visible_y_low) {
-
- int32_t visible_tracks = 0;
- while (visible_tracks < canvas_pointer_y_span ) {
- visible_tracks++;
-
- while (height_list[rtv2->order - (visible_tracks - n)] == 0) {
- /* we're passing through a hidden track */
- n--;
- }
- }
-
- if (tracks[rtv2->order - (canvas_pointer_y_span - n)] != 0x00) {
- clamp_y_axis = true;
- }
-
- } else {
- clamp_y_axis = true;
- }
-
- } else if (canvas_pointer_y_span < 0) {
-
- /*moving down the canvas*/
-
- if ((rtv2->order - (canvas_pointer_y_span - n)) <= visible_y_high) { // we will overflow
-
-
- int32_t visible_tracks = 0;
-
- while (visible_tracks > canvas_pointer_y_span ) {
- visible_tracks--;
-
- while (height_list[rtv2->order - (visible_tracks - n)] == 0) {
- n++;
- }
- }
- if ( tracks[rtv2->order - ( canvas_pointer_y_span - n)] != 0x00) {
- clamp_y_axis = true;
-
- }
- } else {
-
- clamp_y_axis = true;
- }
- }
-
- } else {
-
- /* this is the pointer's track */
- if ((rtv2->order - pointer_y_span) > visible_y_high) { // we will overflow
- clamp_y_axis = true;
- } else if ((rtv2->order - pointer_y_span) < visible_y_low) { // we will underflow
- clamp_y_axis = true;
- }
- }
- if (clamp_y_axis) {
- break;
- }
- }
-
- } else if (drag_info.last_trackview == tv) {
- clamp_y_axis = true;
- }
-
- y_axis_done:
- if (!clamp_y_axis) {
- drag_info.last_trackview = tv;
- }
-
- /************************************************************
- X DELTA COMPUTATION
- ************************************************************/
-
- /* compute the amount of pointer motion in frames, and where
- the region would be if we moved it by that much.
- */
-
- if (drag_info.move_threshold_passed) {
-
- if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
-
- nframes_t sync_frame;
- nframes_t sync_offset;
- int32_t sync_dir;
-
- pending_region_position = drag_info.current_pointer_frame - drag_info.pointer_frame_offset;
-
- sync_offset = rv->region()->sync_offset (sync_dir);
- sync_frame = rv->region()->adjust_to_sync (pending_region_position);
-
- /* we snap if the snap modifier is not enabled.
- */
-
- if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
- snap_to (sync_frame);
- }
-
- if (sync_frame - sync_offset <= sync_frame) {
- pending_region_position = sync_frame - (sync_dir*sync_offset);
- } else {
- pending_region_position = 0;
- }
-
- } else {
- pending_region_position = 0;
- }
-
- if (pending_region_position > max_frames - rv->region()->length()) {
- pending_region_position = drag_info.last_frame_position;
- }
-
- // printf ("3: pending_region_position= %lu %lu\n", pending_region_position, drag_info.last_frame_position );
-
- if (pending_region_position != drag_info.last_frame_position && !drag_info.x_constrained) {
-
- /* now compute the canvas unit distance we need to move the regiondrag_info.last_trackview->order
- to make it appear at the new location.
- */
-
- if (pending_region_position > drag_info.last_frame_position) {
- x_delta = ((double) (pending_region_position - drag_info.last_frame_position) / frames_per_unit);
- } else {
- x_delta = -((double) (drag_info.last_frame_position - pending_region_position) / frames_per_unit);
- }
-
- drag_info.last_frame_position = pending_region_position;
-
- } else {
- x_delta = 0;
- }
-
- } else {
- /* threshold not passed */
-
- x_delta = 0;
- }
-
- /*************************************************************
- PREPARE TO MOVE
- ************************************************************/
-
- if (x_delta == 0 && (pointer_y_span == 0)) {
- /* haven't reached next snap point, and we're not switching
- trackviews. nothing to do.
- */
- return;
- }
-
-
- if (x_delta < 0) {
- for (list<RegionView*>::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) {
-
- RegionView* rv2 = (*i);
-
- // If any regionview is at zero, we need to know so we can stop further leftward motion.
-
- double ix1, ix2, iy1, iy2;
- rv2->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2);
- rv2->get_canvas_group()->i2w (ix1, iy1);
-
- if (ix1 <= 1) {
- x_delta = 0;
- break;
- }
- }
- }
-
- /*************************************************************
- MOTION
- ************************************************************/
-
- bool do_move;
-
- if (drag_info.first_move) {
- if (drag_info.move_threshold_passed) {
- do_move = true;
- } else {
- do_move = false;
- }
- } else {
- do_move = true;
- }
-
- if (do_move) {
-
- pair<set<boost::shared_ptr<Playlist> >::iterator,bool> insert_result;
- const list<RegionView*>& layered_regions = selection->regions.by_layer();
-
- for (list<RegionView*>::const_iterator i = layered_regions.begin(); i != layered_regions.end(); ++i) {
-
- RegionView* rv = (*i);
- double ix1, ix2, iy1, iy2;
- int32_t temp_pointer_y_span = pointer_y_span;
-
- /* get item BBox, which will be relative to parent. so we have
- to query on a child, then convert to world coordinates using
- the parent.
- */
-
- rv->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2);
- rv->get_canvas_group()->i2w (ix1, iy1);
- TimeAxisView* tvp2 = trackview_by_y_position (iy1);
- RouteTimeAxisView* canvas_rtv = dynamic_cast<RouteTimeAxisView*>(tvp2);
- RouteTimeAxisView* temp_rtv;
-
- if ((pointer_y_span != 0) && !clamp_y_axis) {
- y_delta = 0;
- int32_t x = 0;
- for (j = height_list.begin(); j!= height_list.end(); j++) {
- if (x == canvas_rtv->order) {
- /* we found the track the region is on */
- if (x != original_pointer_order) {
- /*this isn't from the same track we're dragging from */
- temp_pointer_y_span = canvas_pointer_y_span;
- }
- while (temp_pointer_y_span > 0) {
- /* we're moving up canvas-wise,
- so we need to find the next track height
- */
- if (j != height_list.begin()) {
- j--;
- }
- if (x != original_pointer_order) {
- /* we're not from the dragged track, so ignore hidden tracks. */
- if ((*j) == 0) {
- temp_pointer_y_span++;
- }
- }
- y_delta -= (*j);
- temp_pointer_y_span--;
- }
- while (temp_pointer_y_span < 0) {
- y_delta += (*j);
- if (x != original_pointer_order) {
- if ((*j) == 0) {
- temp_pointer_y_span--;
- }
- }
-
- if (j != height_list.end()) {
- j++;
- }
- temp_pointer_y_span++;
- }
- /* find out where we'll be when we move and set height accordingly */
-
- tvp2 = trackview_by_y_position (iy1 + y_delta);
- temp_rtv = dynamic_cast<RouteTimeAxisView*>(tvp2);
- rv->set_y_position_and_height (0, temp_rtv->height);
-
- /* if you un-comment the following, the region colours will follow the track colours whilst dragging,
- personally, i think this can confuse things, but never mind.
- */
-
- //const GdkColor& col (temp_rtv->view->get_region_color());
- //rv->set_color (const_cast<GdkColor&>(col));
- break;
- }
- x++;
- }
- }
-
- /* prevent the regionview from being moved to before
- the zero position on the canvas.
- */
- /* clamp */
-
- if (x_delta < 0) {
- if (-x_delta > ix1) {
- x_delta = -ix1;
- }
- } else if ((x_delta > 0) && (rv->region()->last_frame() > max_frames - x_delta)) {
- x_delta = max_frames - rv->region()->last_frame();
- }
-
-
- if (drag_info.first_move) {
-
- /* hide any dependent views */
-
- rv->get_time_axis_view().hide_dependent_views (*rv);
-
- /* this is subtle. raising the regionview itself won't help,
- because raise_to_top() just puts the item on the top of
- its parent's stack. so, we need to put the trackview canvas_display group
- on the top, since its parent is the whole canvas.
- */
-
- rv->get_canvas_group()->raise_to_top();
- rv->get_time_axis_view().canvas_display->raise_to_top();
- cursor_group->raise_to_top();
-
- rv->fake_set_opaque (true);
- }
-
- if (drag_info.brushing) {
- mouse_brush_insert_region (rv, pending_region_position);
- } else {
- rv->move (x_delta, y_delta);
- }
-
- } /* foreach region */
-
- } /* if do_move */
-
- if (drag_info.first_move && drag_info.move_threshold_passed) {
- cursor_group->raise_to_top();
- drag_info.first_move = false;
- }
-
- if (x_delta != 0 && !drag_info.brushing) {
- show_verbose_time_cursor (drag_info.last_frame_position, 10);
- }
-}
-
-void
-Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
-{
- nframes_t where;
- RegionView* rvdi = reinterpret_cast<RegionView *> (drag_info.data);
- pair<set<boost::shared_ptr<Playlist> >::iterator,bool> insert_result;
- bool nocommit = true;
- double speed;
- RouteTimeAxisView* rtv;
- bool regionview_y_movement;
- bool regionview_x_movement;
- vector<RegionView*> copies;
- list <boost::shared_ptr<Playlist > > used_playlists;
- list <sigc::connection > used_connections;
- bool preserve_selection = false;
-
- /* first_move is set to false if the regionview has been moved in the
- motion handler.
- */
-
- if (drag_info.first_move) {
- /* just a click */
- goto out;
- }
-
- nocommit = false;
-
- /* The regionview has been moved at some stage during the grab so we need
- to account for any mouse movement between this event and the last one.
- */
-
- region_drag_motion_callback (item, event);
-
- if (drag_info.brushing) {
- /* all changes were made during motion event handlers */
-
- if (drag_info.copy) {
- for (list<RegionView*>::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
- copies.push_back (*i);
- }
- }
-
- goto out;
- }
-
- /* adjust for track speed */
- speed = 1.0;
-
- rtv = dynamic_cast<RouteTimeAxisView*> (drag_info.last_trackview);
- if (rtv && rtv->get_diskstream()) {
- speed = rtv->get_diskstream()->speed();
- }
-
- regionview_x_movement = (drag_info.last_frame_position != (nframes_t) (rvdi->region()->position()/speed));
- regionview_y_movement = (drag_info.last_trackview != &rvdi->get_time_axis_view());
-
- //printf ("last_frame: %s position is %lu %g\n", rv->get_time_axis_view().name().c_str(), drag_info.last_frame_position, speed);
- //printf ("last_rackview: %s \n", drag_info.last_trackview->name().c_str());
-
- char* op_string;
-
- if (drag_info.copy) {
- if (drag_info.x_constrained) {
- op_string = _("fixed time region copy");
- } else {
- op_string = _("region copy");
- }
- } else {
- if (drag_info.x_constrained) {
- op_string = _("fixed time region drag");
- } else {
- op_string = _("region drag");
- }
- }
-
- begin_reversible_command (op_string);
-
- if (regionview_y_movement) {
-
- /* moved to a different audio track. */
-
- for (list<RegionView*>::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ) {
-
- RegionView* rv = (*i);
-
- double ix1, ix2, iy1, iy2;
-
- rv->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2);
- rv->get_canvas_group()->i2w (ix1, iy1);
-
- RouteTimeAxisView* rtv2 = dynamic_cast<RouteTimeAxisView*>(trackview_by_y_position (iy1));
-
- boost::shared_ptr<Playlist> to_playlist = rtv2->playlist();
-
- if (! to_playlist->frozen()) {
- /*
- we haven't seen this playlist before.
- we want to freeze it because we don't want to relayer per-region.
- its much better to do that just once if the playlist is large.
- */
-
- /*
- connect so the selection is changed when the new regionview finally appears (after thaw).
- keep track of it so we can disconnect later.
- */
-
- sigc::connection c = rtv2->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_and_select_new_region_view));
- used_connections.push_back (c);
-
- /* undo */
- session->add_command (new MementoCommand<Playlist>(*to_playlist, &to_playlist->get_state(), 0));
-
- /* remember used playlists so we can thaw them later */
- used_playlists.push_back(to_playlist);
- to_playlist->freeze();
- }
-
- where = (nframes_t) (unit_to_frame (ix1) * speed);
- boost::shared_ptr<Region> new_region (RegionFactory::create (rv->region()));
-
- if (!drag_info.copy) {
-
-
- /* the region that used to be in the old playlist is not
- moved to the new one - we make a copy of it. as a result,
- any existing editor for the region should no longer be
- visible.
- */
-
- RouteTimeAxisView* from_playlist_rtv = dynamic_cast<RouteTimeAxisView*>(&(*i)->get_trackview());
- boost::shared_ptr<Playlist> from_playlist = from_playlist_rtv->playlist();
-
- if (! from_playlist->frozen()) {
- from_playlist->freeze();
- used_playlists.push_back(from_playlist);
-
- sigc::connection c = rtv2->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_and_select_new_region_view));
- used_connections.push_back (c);
-
- session->add_command (new MementoCommand<Playlist>(*from_playlist, &from_playlist->get_state(), 0));
- }
-
- rv->hide_region_editor();
- rv->fake_set_opaque (false);
-
- from_playlist->remove_region ((rv->region()));
-
- } else {
-
- /* the regionview we dragged around is a temporary copy, queue it for deletion */
-
- copies.push_back (rv);
- }
-
- latest_regionview = 0;
-
- to_playlist->add_region (new_region, where);
-
- /* OK, this is where it gets tricky. If the playlist was being used by >1 tracks, and the region
- was selected in all of them, then removing it from the playlist will have removed all
- trace of it from the selection (i.e. there were N regions selected, we removed 1,
- but since its the same playlist for N tracks, all N tracks updated themselves, removed the
- corresponding regionview, and the selection is now empty).
-
- this could have invalidated any and all iterators into the region selection.
-
- the heuristic we use here is: if the region selection is empty, break out of the loop
- here. if the region selection is not empty, then restart the loop because we know that
- we must have removed at least the region(view) we've just been working on as well as any
- that we processed on previous iterations.
-
- EXCEPT .... if we are doing a copy drag, then the selection hasn't been modified and
- we can just iterate.
-
- */
-
- if (drag_info.copy) {
- ++i;
- } else {
- if (selection->regions.empty()) {
- break;
- } else {
- /*
- XXX see above .. but we just froze the playlists.. we have to keep iterating, right?
- */
-
- //i = selection->regions.by_layer().begin();
- ++i;
- }
- }
- }
-
- } else {
-
- /* motion within a single track */
-
- list<RegionView*> regions = selection->regions.by_layer();
-
- for (list<RegionView*>::iterator i = regions.begin(); i != regions.end(); ++i) {
-
- RegionView* rv = (*i);
- boost::shared_ptr<Playlist> to_playlist = (*i)->region()->playlist();
- RouteTimeAxisView* from_rtv = dynamic_cast<RouteTimeAxisView*> (&(rv->get_time_axis_view()));
-
- if (!rv->region()->can_move()) {
- continue;
- }
-
- if (regionview_x_movement) {
- double ownspeed = 1.0;
-
- if (from_rtv && from_rtv->get_diskstream()) {
- ownspeed = from_rtv->get_diskstream()->speed();
- }
-
- /* base the new region position on the current position of the regionview.*/
-
- double ix1, ix2, iy1, iy2;
-
- rv->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2);
- rv->get_canvas_group()->i2w (ix1, iy1);
- where = (nframes_t) (unit_to_frame (ix1) * ownspeed);
-
- } else {
-
- where = rv->region()->position();
- }
-
- if (! to_playlist->frozen()) {
- sigc::connection c = from_rtv->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_and_select_new_region_view));
- used_connections.push_back (c);
-
- /* add the undo */
- session->add_command (new MementoCommand<Playlist>(*to_playlist, &to_playlist->get_state(), 0));
-
- used_playlists.push_back(to_playlist);
- to_playlist->freeze();
- }
-
- if (drag_info.copy) {
-
- boost::shared_ptr<Region> newregion;
- boost::shared_ptr<Region> ar;
- boost::shared_ptr<Region> mr;
-
- if ((ar = boost::dynamic_pointer_cast<AudioRegion>(rv->region())) != 0) {
- newregion = RegionFactory::create (ar);
- } else if ((mr = boost::dynamic_pointer_cast<MidiRegion>(rv->region())) != 0) {
- newregion = RegionFactory::create (mr);
- }
-
- /* add it */
-
- to_playlist->add_region (newregion, (nframes_t) (where * from_rtv->get_diskstream()->speed()));
-
- /* if the original region was locked, we don't care for the new one */
-
- newregion->set_locked (false);
- copies.push_back (rv);
-
- } else {
-
- /* just change the model */
-
- rv->region()->set_position (where, (void*) this);
- preserve_selection = true;
-
- }
-
- }
-
- }
- if (! preserve_selection) {
- //selection->clear_regions();
- }
- while (used_playlists.size() > 0) {
-
- list <boost::shared_ptr<Playlist > >::iterator i = used_playlists.begin();
- (*i)->thaw();
-
- if (used_connections.size()) {
- sigc::connection c = used_connections.front();
- c.disconnect();
- used_connections.pop_front();
- }
- /* add the redo */
-
- session->add_command (new MementoCommand<Playlist>(*(*i), 0, &(*i)->get_state()));
- used_playlists.pop_front();
- }
-
- out:
-
- if (!nocommit) {
- commit_reversible_command ();
- }
-
- for (vector<RegionView*>::iterator x = copies.begin(); x != copies.end(); ++x) {
- delete *x;
- }
-}
-
-
-void
-Editor::create_region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
-{
- if (drag_info.move_threshold_passed) {
- if (drag_info.first_move) {
- // TODO: create region-create-drag region view here
- drag_info.first_move = false;
- }
-
- // TODO: resize region-create-drag region view here
- }
-}
-
-void
-Editor::create_region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
-{
- MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*> (drag_info.last_trackview);
- if (!mtv)
- return;
-
- const boost::shared_ptr<MidiDiskstream> diskstream =
- boost::dynamic_pointer_cast<MidiDiskstream>(mtv->view()->trackview().track()->diskstream());
-
- if (!diskstream) {
- warning << "Cannot create non-MIDI region" << endl;
- return;
- }
-
- if (drag_info.first_move) {
- begin_reversible_command (_("create region"));
- XMLNode &before = mtv->playlist()->get_state();
-
- nframes_t start = drag_info.grab_frame;
- snap_to (start, -1);
- const Meter& m = session->tempo_map().meter_at(start);
- const Tempo& t = session->tempo_map().tempo_at(start);
- double length = m.frames_per_bar(t, session->frame_rate());
-
- boost::shared_ptr<Source> src = session->create_midi_source_for_session(*diskstream.get());
-
- mtv->playlist()->add_region (boost::dynamic_pointer_cast<MidiRegion>(RegionFactory::create(
- src, 0, length, PBD::basename_nosuffix(src->name()))), start);
- XMLNode &after = mtv->playlist()->get_state();
- session->add_command(new MementoCommand<Playlist>(*mtv->playlist().get(), &before, &after));
- commit_reversible_command();
-
- } else {
- create_region_drag_motion_callback (item, event);
- // TODO: create region-create-drag region here
- }
-}
-
-void
-Editor::region_view_item_click (AudioRegionView& rv, GdkEventButton* event)
-{
- /* Either add to or set the set the region selection, unless
- this is an alignment click (control used)
- */
-
- if (Keyboard::modifier_state_contains (event->state, Keyboard::Control)) {
- TimeAxisView* tv = &rv.get_time_axis_view();
- RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(tv);
- double speed = 1.0;
- if (rtv && rtv->is_track()) {
- speed = rtv->get_diskstream()->speed();
- }
-
- if (Keyboard::modifier_state_equals (event->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Alt))) {
-
- align_region (rv.region(), SyncPoint, (nframes_t) (edit_cursor->current_frame * speed));
-
- } else if (Keyboard::modifier_state_equals (event->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Shift))) {
-
- align_region (rv.region(), End, (nframes_t) (edit_cursor->current_frame * speed));
-
- } else {
-
- align_region (rv.region(), Start, (nframes_t) (edit_cursor->current_frame * speed));
- }
- }
-}
-
-void
-Editor::show_verbose_time_cursor (nframes_t frame, double offset, double xpos, double ypos)
-{
- char buf[128];
- SMPTE::Time smpte;
- BBT_Time bbt;
- int hours, mins;
- nframes_t frame_rate;
- float secs;
-
- if (session == 0) {
- return;
- }
-
- switch (Profile->get_small_screen() ? ARDOUR_UI::instance()->primary_clock.mode () : ARDOUR_UI::instance()->secondary_clock.mode ()) {
- case AudioClock::BBT:
- session->bbt_time (frame, bbt);
- snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bbt.bars, bbt.beats, bbt.ticks);
- break;
-
- case AudioClock::SMPTE:
- session->smpte_time (frame, smpte);
- snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32, smpte.hours, smpte.minutes, smpte.seconds, smpte.frames);
- break;
-
- case AudioClock::MinSec:
- /* XXX this is copied from show_verbose_duration_cursor() */
- frame_rate = session->frame_rate();
- hours = frame / (frame_rate * 3600);
- frame = frame % (frame_rate * 3600);
- mins = frame / (frame_rate * 60);
- frame = frame % (frame_rate * 60);
- secs = (float) frame / (float) frame_rate;
- snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%.4f", hours, mins, secs);
- break;
-
- default:
- snprintf (buf, sizeof(buf), "%u", frame);
- break;
- }
-
- if (xpos >= 0 && ypos >=0) {
- set_verbose_canvas_cursor (buf, xpos + offset, ypos + offset);
- }
- else {
- set_verbose_canvas_cursor (buf, drag_info.current_pointer_x + offset, drag_info.current_pointer_y + offset);
- }
- show_verbose_canvas_cursor ();
-}
-
-void
-Editor::show_verbose_duration_cursor (nframes_t start, nframes_t end, double offset, double xpos, double ypos)
-{
- char buf[128];
- SMPTE::Time smpte;
- BBT_Time sbbt;
- BBT_Time ebbt;
- int hours, mins;
- nframes_t distance, frame_rate;
- float secs;
- Meter meter_at_start(session->tempo_map().meter_at(start));
-
- if (session == 0) {
- return;
- }
-
- switch (ARDOUR_UI::instance()->secondary_clock.mode ()) {
- case AudioClock::BBT:
- session->bbt_time (start, sbbt);
- session->bbt_time (end, ebbt);