X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Feditor_ops.cc;h=b70d0f06647ec4088b86be5c501061515b7091ad;hb=fd9ba531bb9db001fea5105f0d374923ca9e6db4;hp=05ecc23c32654ad19819889fc8ae104102c53dd1;hpb=5573b6a049646fd0fe10d4d79f98cf272ee1f107;p=ardour.git diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 05ecc23c32..b70d0f0664 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -44,6 +44,7 @@ #include "ardour/dB.h" #include "ardour/location.h" #include "ardour/midi_region.h" +#include "ardour/midi_track.h" #include "ardour/operations.h" #include "ardour/playlist_factory.h" #include "ardour/quantize.h" @@ -1327,14 +1328,30 @@ Editor::tav_zoom_smooth (bool coarser, bool force_all) _routes->resume_redisplay (); } +bool +Editor::clamp_frames_per_unit (double& fpu) const +{ + bool clamped = false; + + if (fpu < 2.0) { + fpu = 2.0; + clamped = true; + } + + if (max_framepos / fpu < 800) { + fpu = max_framepos / 800.0; + clamped = true; + } + + return clamped; +} + void Editor::temporal_zoom_step (bool coarser) { ENSURE_GUI_THREAD (*this, &Editor::temporal_zoom_step, coarser) - double nfpu; - - nfpu = frames_per_unit; + double nfpu = frames_per_unit; if (coarser) { nfpu = min (9e6, nfpu * 1.61803399); @@ -1346,9 +1363,11 @@ Editor::temporal_zoom_step (bool coarser) } void -Editor::temporal_zoom (gdouble fpu) +Editor::temporal_zoom (double fpu) { - if (!_session) return; + if (!_session) { + return; + } framepos_t current_page = current_page_frames(); framepos_t current_leftmost = leftmost_frame; @@ -1362,9 +1381,8 @@ Editor::temporal_zoom (gdouble fpu) double nfpu; double l; - /* XXX this limit is also in ::set_frames_per_unit() */ - - if (frames_per_unit <= 1.0 && fpu <= frames_per_unit) { + clamp_frames_per_unit (fpu); + if (fpu == frames_per_unit) { return; } @@ -1829,13 +1847,13 @@ Editor::jump_forward_to_mark () return; } - Location *location = _session->locations()->first_location_after (playhead_cursor->current_frame); + framepos_t pos = _session->locations()->first_mark_after (playhead_cursor->current_frame); - if (location) { - _session->request_locate (location->start(), _session->transport_rolling()); - } else { - _session->request_locate (_session->current_end_frame()); + if (pos < 0) { + return; } + + _session->request_locate (pos, _session->transport_rolling()); } void @@ -1845,13 +1863,13 @@ Editor::jump_backward_to_mark () return; } - Location *location = _session->locations()->first_location_before (playhead_cursor->current_frame); + framepos_t pos = _session->locations()->first_mark_before (playhead_cursor->current_frame); - if (location) { - _session->request_locate (location->start(), _session->transport_rolling()); - } else { - _session->goto_start (); + if (pos < 0) { + return; } + + _session->request_locate (pos, _session->transport_rolling()); } void @@ -2089,7 +2107,7 @@ Editor::transition_to_rolling (bool fwd) } if (_session->config.get_external_sync()) { - switch (_session->config.get_sync_source()) { + switch (Config->get_sync_source()) { case JACK: break; default: @@ -2152,6 +2170,55 @@ Editor::play_selection () _session->request_play_range (&selection->time, true); } +framepos_t +Editor::get_preroll () +{ + return 1.0 /*Config->get_edit_preroll_seconds()*/ * _session->frame_rate(); +} + + +void +Editor::maybe_locate_with_edit_preroll ( framepos_t location ) +{ + if ( _session->transport_rolling() || !Config->get_always_play_range() ) + return; + + location -= get_preroll(); + + //don't try to locate before the beginning of time + if ( location < 0 ) + location = 0; + + //if follow_playhead is on, keep the playhead on the screen + if ( _follow_playhead ) + if ( location < leftmost_frame ) + location = leftmost_frame; + + _session->request_locate( location ); +} + +void +Editor::play_with_preroll () +{ + if (selection->time.empty()) { + return; + } else { + framepos_t preroll = get_preroll(); + + framepos_t start = 0; + if (selection->time[clicked_selection].start > preroll) + start = selection->time[clicked_selection].start - preroll; + + framepos_t end = selection->time[clicked_selection].end + preroll; + + AudioRange ar (start, end, 0); + list lar; + lar.push_back (ar); + + _session->request_play_range (&lar, true); + } +} + void Editor::play_location (Location& location) { @@ -2316,7 +2383,6 @@ Editor::rename_region () d.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); d.set_size_request (300, -1); - d.set_position (Gtk::WIN_POS_MOUSE); entry.set_text (rs.front()->region()->name()); entry.select_region (0, -1); @@ -2659,7 +2725,7 @@ Editor::separate_region_from_selection () returns a single range. */ - if (mouse_mode == MouseRange && !selection->time.empty()) { + if (!selection->time.empty()) { separate_regions_between (selection->time); @@ -3220,8 +3286,10 @@ Editor::trim_region (bool front) if (front) { (*i)->region()->trim_front (where); + maybe_locate_with_edit_preroll ( where ); } else { (*i)->region()->trim_end (where); + maybe_locate_with_edit_preroll ( where ); } _session->add_command (new StatefulDiffCommand ((*i)->region())); @@ -3393,7 +3461,6 @@ Editor::freeze_thread () /* create event pool because we may need to talk to the session */ SessionEvent::create_per_thread_pool ("freeze events", 64); /* create per-thread buffers for process() tree to use */ - current_interthread_info->process_thread.init (); current_interthread_info->process_thread.get_buffers (); clicked_routeview->audio_track()->freeze_me (*current_interthread_info); current_interthread_info->done = true; @@ -3484,7 +3551,7 @@ Editor::bounce_range_selection (bool replace, bool enable_processing) if (rtv && rtv->track() && replace && enable_processing && !rtv->track()->bounceable (rtv->track()->main_outs(), false)) { MessageDialog d ( _("You can't perform this operation because the processing of the signal " - "will cause one or more of the tracks will end up with a region with more channels than this track has inputs.\n\n" + "will cause one or more of the tracks to end up with a region with more channels than this track has inputs.\n\n" "You can do this without processing, which is a different operation.") ); d.set_title (_("Cannot bounce")); @@ -3574,7 +3641,7 @@ Editor::copy () bool Editor::can_cut_copy () const { - switch (current_mouse_mode()) { + switch (effective_mouse_mode()) { case MouseObject: if (!selection->regions.empty() || !selection->points.empty()) { @@ -3633,7 +3700,8 @@ Editor::cut_copy (CutCopyOp op) } } - cut_buffer->clear (); + if ( op != Clear ) //"Delete" doesn't change copy/paste buf + cut_buffer->clear (); if (entered_marker) { @@ -3652,7 +3720,7 @@ Editor::cut_copy (CutCopyOp op) if (internal_editing()) { - switch (current_mouse_mode()) { + switch (effective_mouse_mode()) { case MouseObject: case MouseRange: cut_copy_midi (op); @@ -3663,19 +3731,62 @@ Editor::cut_copy (CutCopyOp op) } else { - RegionSelection rs; + RegionSelection rs; - /* we only want to cut regions if some are selected */ + /* we only want to cut regions if some are selected */ - if (doing_object_stuff()) { - rs = get_regions_from_selection (); - if (!rs.empty() || !selection->points.empty()) { + if (!selection->regions.empty()) { + rs = selection->regions; + } + switch (effective_mouse_mode()) { +/* + * case MouseGain: { + //find regions's gain line + AudioRegionView *rview = dynamic_cast(clicked_regionview); + AutomationTimeAxisView *tview = dynamic_cast(clicked_trackview); + if (rview) { + AudioRegionGainLine *line = rview->get_gain_line(); + if (!line) break; + + //cut region gain points in the selection + AutomationList& alist (line->the_list()); + XMLNode &before = alist.get_state(); + AutomationList* what_we_got = 0; + if ((what_we_got = alist.cut (selection->time.front().start - rview->audio_region()->position(), selection->time.front().end - rview->audio_region()->position())) != 0) { + session->add_command(new MementoCommand(alist, &before, &alist.get_state())); + delete what_we_got; + what_we_got = 0; + } + + rview->set_envelope_visible(true); + rview->audio_region()->set_envelope_active(true); + + } else if (tview) { + AutomationLine *line = *(tview->lines.begin()); + if (!line) break; + + //cut auto points in the selection + AutomationList& alist (line->the_list()); + XMLNode &before = alist.get_state(); + AutomationList* what_we_got = 0; + if ((what_we_got = alist.cut (selection->time.front().start, selection->time.front().end)) != 0) { + session->add_command(new MementoCommand(alist, &before, &alist.get_state())); + delete what_we_got; + what_we_got = 0; + } + } else + break; + } break; +*/ + case MouseObject: + case MouseRange: + if (!rs.empty() || !selection->points.empty()) { begin_reversible_command (opname + _(" objects")); if (!rs.empty()) { cut_copy_regions (op, rs); - + if (op == Cut || op == Delete) { selection->clear_regions (); } @@ -3688,16 +3799,11 @@ Editor::cut_copy (CutCopyOp op) selection->clear_points (); } } - commit_reversible_command (); - goto out; - } - if (!selection->time.empty() && (_join_object_range_state == JOIN_OBJECT_RANGE_NONE)) { - /* don't cause suprises */ - goto out; - } - } - if (doing_range_stuff()) { + commit_reversible_command (); + break; + } + if (selection->time.empty()) { framepos_t start, end; if (!get_edit_op_range (start, end)) { @@ -3705,18 +3811,22 @@ Editor::cut_copy (CutCopyOp op) } selection->set (start, end); } - + begin_reversible_command (opname + _(" range")); cut_copy_ranges (op); commit_reversible_command (); - + if (op == Cut || op == Delete) { selection->clear_time (); } + + break; + + default: + break; } } - out: if (op == Delete || op == Cut || op == Clear) { _drags->abort (); } @@ -4730,8 +4840,6 @@ Editor::insert_patch_change (bool from_context) const framepos_t p = get_preferred_edit_position (false, from_context); - cerr << "Got " << rs.size() << " regions to add patch change to\n"; - /* XXX: bit of a hack; use the MIDNAM from the first selected region; there may be more than one, but the PatchChangeDialog can only offer one set of patch menus. @@ -4943,6 +5051,30 @@ Editor::toggle_region_lock () _session->commit_reversible_command (); } +void +Editor::toggle_region_video_lock () +{ + if (_ignore_region_action) { + return; + } + + RegionSelection rs = get_regions_from_selection_and_entered (); + + if (!_session || rs.empty()) { + return; + } + + _session->begin_reversible_command (_("Toggle Video Lock")); + + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { + (*i)->region()->clear_changes (); + (*i)->region()->set_video_locked (!(*i)->region()->video_locked()); + _session->add_command (new StatefulDiffCommand ((*i)->region())); + } + + _session->commit_reversible_command (); +} + void Editor::toggle_region_lock_style () { @@ -5370,14 +5502,15 @@ Editor::set_playhead_cursor () _session->request_locate (where, _session->transport_rolling()); } } + + if ( Config->get_always_play_range() ) + cancel_time_selection(); } void Editor::split_region () { - if (((mouse_mode == MouseRange) || - (mouse_mode != MouseObject && _join_object_range_state == JOIN_OBJECT_RANGE_RANGE)) && - !selection->time.empty()) { + if ( !selection->time.empty()) { separate_regions_between (selection->time); return; } @@ -5395,8 +5528,7 @@ Editor::split_region () struct EditorOrderRouteSorter { bool operator() (boost::shared_ptr a, boost::shared_ptr b) { - /* use of ">" forces the correct sort order */ - return a->order_key ("editor") < b->order_key ("editor"); + return a->order_key (EditorSort) < b->order_key (EditorSort); } }; @@ -5761,7 +5893,9 @@ Editor::define_one_bar (framepos_t start, framepos_t end) } else if (t.frame() == start) { _session->tempo_map().change_existing_tempo_at (start, beats_per_minute, t.note_type()); } else { - _session->tempo_map().add_tempo (Tempo (beats_per_minute, t.note_type()), start); + Timecode::BBT_Time bbt; + _session->tempo_map().bbt_time (start, bbt); + _session->tempo_map().add_tempo (Tempo (beats_per_minute, t.note_type()), bbt); } XMLNode& after (_session->tempo_map().get_state()); @@ -6813,3 +6947,26 @@ Editor::uncombine_regions () commit_reversible_command (); } +void +Editor::toggle_midi_input_active (bool flip_others) +{ + bool onoff; + boost::shared_ptr rl (new RouteList); + + for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) { + RouteTimeAxisView *rtav = dynamic_cast(*i); + + if (!rtav) { + continue; + } + + boost::shared_ptr mt = rtav->midi_track(); + + if (mt) { + rl->push_back (rtav->route()); + onoff = !mt->input_active(); + } + } + + _session->set_exclusive_input_active (rl, onoff, flip_others); +}