X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fsurfaces%2Fcontrol_protocol%2Fbasic_ui.cc;h=7836eef319697a519badcea384b09f19faa3dba1;hb=ea8d089e3c1374da1cb693928bce01e5e722d1eb;hp=13b41ba373b9c7f561085c20bdbc9cefd3a5e045;hpb=c5b93e2a019193f4aec47191b24e37e6ffef99b3;p=ardour.git diff --git a/libs/surfaces/control_protocol/basic_ui.cc b/libs/surfaces/control_protocol/basic_ui.cc index 13b41ba373..7836eef319 100644 --- a/libs/surfaces/control_protocol/basic_ui.cc +++ b/libs/surfaces/control_protocol/basic_ui.cc @@ -24,10 +24,11 @@ #include "ardour/session.h" #include "ardour/location.h" #include "ardour/tempo.h" +#include "ardour/utils.h" #include "control_protocol/basic_ui.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace ARDOUR; @@ -70,18 +71,43 @@ BasicUI::access_action ( std::string action_path ) void BasicUI::loop_toggle () { + if (!session) { + return; + } + + Location * looploc = session->locations()->auto_loop_location(); + + if (!looploc) { + return; + } + if (session->get_play_loop()) { + + /* looping enabled, our job is to disable it */ + session->request_play_loop (false); + } else { - session->request_play_loop (true); - if (!session->transport_rolling()) { - session->request_transport_speed (1.0); + + /* looping not enabled, our job is to enable it. + + loop-is-NOT-mode: this action always starts the transport rolling. + loop-IS-mode: this action simply sets the loop play mechanism, but + does not start transport. + */ + if (Config->get_loop_is_mode()) { + session->request_play_loop (true, false); + } else { + session->request_play_loop (true, true); } } + + //show the loop markers + looploc->set_hidden (false, this); } void -BasicUI::loop_location (framepos_t start, framepos_t end) +BasicUI::loop_location (samplepos_t start, samplepos_t end) { Location* tll; if ((tll = session->locations()->auto_loop_location()) == 0) { @@ -95,9 +121,9 @@ BasicUI::loop_location (framepos_t start, framepos_t end) } void -BasicUI::goto_start () +BasicUI::goto_start (bool and_roll) { - session->goto_start (); + session->goto_start (and_roll); } void @@ -115,7 +141,7 @@ BasicUI::goto_end () void BasicUI::add_marker (const std::string& markername) { - framepos_t where = session->audible_frame(); + samplepos_t where = session->audible_sample(); Location *location = new Location (*session, where, where, markername, Location::IsMark); session->begin_reversible_command (_("add marker")); XMLNode &before = session->locations()->get_state(); @@ -135,7 +161,7 @@ BasicUI::remove_marker_at_playhead () //find location(s) at this time Locations::LocationList locs; - session->locations()->find_all_between (session->audible_frame(), session->audible_frame()+1, locs, Location::Flags(0)); + session->locations()->find_all_between (session->audible_sample(), session->audible_sample()+1, locs, Location::Flags(0)); for (Locations::LocationList::iterator i = locs.begin(); i != locs.end(); ++i) { if ((*i)->is_mark()) { session->locations()->remove (*i); @@ -174,22 +200,56 @@ BasicUI::transport_stop () void BasicUI::transport_play (bool from_last_start) { - bool rolling = session->transport_rolling (); + if (!session) { + return; + } - if (session->get_play_loop()) { - session->request_play_loop (false); + if (session->is_auditioning()) { + return; } - if (session->get_play_range ()) { - session->request_play_range (0); +#if 0 + if (session->config.get_external_sync()) { + switch (Config->get_sync_source()) { + case Engine: + break; + default: + /* transport controlled by the master */ + return; + } } +#endif + + bool rolling = session->transport_rolling(); + + if (session->get_play_loop()) { + + /* If loop playback is not a mode, then we should cancel + it when this action is requested. If it is a mode + we just leave it in place. + */ - if (from_last_start && rolling) { - session->request_locate (session->last_transport_start(), true); + if (!Config->get_loop_is_mode()) { + /* XXX it is not possible to just leave seamless loop and keep + playing at present (nov 4th 2009) + */ + if (!Config->get_seamless_loop()) { + /* stop loop playback and stop rolling */ + session->request_play_loop (false, true); + } else if (rolling) { + /* stop loop playback but keep rolling */ + session->request_play_loop (false, false); + } + } + } else if (session->get_play_range () ) { + /* stop playing a range if we currently are */ + session->request_play_range (0, true); } - session->request_transport_speed (1.0f); + if (!rolling) { + session->request_transport_speed (1.0f); + } } void @@ -207,10 +267,22 @@ BasicUI::rec_enable_toggle () break; case Session::Recording: case Session::Enabled: - session->disable_record (true); + session->disable_record (false, true); } } +void +BasicUI::all_tracks_rec_in () +{ + session->set_all_tracks_record_enabled (true); +} + +void +BasicUI::all_tracks_rec_out () +{ + session->set_all_tracks_record_enabled (false); +} + void BasicUI::save_state () { @@ -220,7 +292,7 @@ BasicUI::save_state () void BasicUI::prev_marker () { - framepos_t pos = session->locations()->first_mark_before (session->transport_frame()); + samplepos_t pos = session->locations()->first_mark_before (session->transport_sample()); if (pos >= 0) { session->request_locate (pos, session->transport_rolling()); @@ -232,7 +304,7 @@ BasicUI::prev_marker () void BasicUI::next_marker () { - framepos_t pos = session->locations()->first_mark_after (session->transport_frame()); + samplepos_t pos = session->locations()->first_mark_after (session->transport_sample()); if (pos >= 0) { session->request_locate (pos, session->transport_rolling()); @@ -256,13 +328,13 @@ BasicUI::get_transport_speed () void BasicUI::undo () { - session->undo (1); + access_action ("Editor/undo"); } void BasicUI::redo () { - session->redo (1); + access_action ("Editor/redo"); } void @@ -303,14 +375,14 @@ BasicUI::set_record_enable (bool yn) } } -framepos_t -BasicUI::transport_frame () +samplepos_t +BasicUI::transport_sample () { - return session->transport_frame(); + return session->transport_sample(); } void -BasicUI::locate (framepos_t where, bool roll_after_locate) +BasicUI::locate (samplepos_t where, bool roll_after_locate) { session->request_locate (where, roll_after_locate); } @@ -318,49 +390,111 @@ BasicUI::locate (framepos_t where, bool roll_after_locate) void BasicUI::jump_by_seconds (double secs) { - framepos_t current = session->transport_frame(); - double s = (double) current / (double) session->nominal_frame_rate(); - + samplepos_t current = session->transport_sample(); + double s = (double) current / (double) session->nominal_sample_rate(); + s+= secs; - if (s < 0) current = 0; - s = s * session->nominal_frame_rate(); - + if (s < 0) { + s = 0; + } + s = s * session->nominal_sample_rate(); + session->request_locate ( floor(s) ); } void BasicUI::jump_by_bars (double bars) { - Timecode::BBT_Time bbt; TempoMap& tmap (session->tempo_map()); - tmap.bbt_time (session->transport_frame(), bbt); + Timecode::BBT_Time bbt (tmap.bbt_at_sample (session->transport_sample())); bars += bbt.bars; - if (bars < 0) bars = 0; - + if (bars < 0) { + bars = 0; + } + AnyTime any; any.type = AnyTime::BBT; any.bbt.bars = bars; - - session->request_locate ( session->convert_to_frames (any) ); + + session->request_locate ( session->convert_to_samples (any) ); +} + +void +BasicUI::toggle_monitor_mute () +{ + if (session->monitor_out()) { + boost::shared_ptr mon = session->monitor_out()->monitor_control(); + if (mon->cut_all ()) { + mon->set_cut_all (false); + } else { + mon->set_cut_all (true); + } + } } -void BasicUI::mark_in () { access_action("Editor/start-range"); } -void BasicUI::mark_out () { access_action("Editor/finish-range"); } +void +BasicUI::toggle_monitor_dim () +{ + if (session->monitor_out()) { + boost::shared_ptr mon = session->monitor_out()->monitor_control(); + if (mon->dim_all ()) { + mon->set_dim_all (false); + } else { + mon->set_dim_all (true); + } + } +} + +void +BasicUI::toggle_monitor_mono () +{ + if (session->monitor_out()) { + boost::shared_ptr mon = session->monitor_out()->monitor_control(); + if (mon->mono()) { + mon->set_mono (false); + } else { + mon->set_mono (true); + } + } +} + +void +BasicUI::midi_panic () +{ + session->midi_panic (); +} + +void +BasicUI::toggle_click () +{ + bool state = !Config->get_clicking(); + Config->set_clicking (state); +} + +void +BasicUI::toggle_roll () +{ + if (session->transport_rolling()) { + transport_stop (); + } else { + transport_play (false); + } +} -void BasicUI::toggle_click () { access_action("Transport/ToggleClick"); } -void BasicUI::midi_panic () { access_action("MIDI/panic"); } -void BasicUI::toggle_roll () { access_action("Transport/ToggleRoll"); } -void BasicUI::stop_forget () { access_action("Transport/ToggleRollForgetCapture"); } +void +BasicUI::stop_forget () +{ + session->request_stop (true, true); +} + +void BasicUI::mark_in () { access_action("Common/start-range-from-playhead"); } +void BasicUI::mark_out () { access_action("Common/finish-range-from-playhead"); } void BasicUI::set_punch_range () { access_action("Editor/set-punch-from-edit-range"); } void BasicUI::set_loop_range () { access_action("Editor/set-loop-from-edit-range"); } void BasicUI::set_session_range () { access_action("Editor/set-session-from-edit-range"); } -void BasicUI::toggle_monitor_mute () { /*access_action("Editor/toggle_monitor_mute"); */ } -void BasicUI::toggle_monitor_dim () { /*access_action("Editor/toggle_monitor_dim"); */ } -void BasicUI::toggle_monitor_mono () { /*access_action("Editor/toggle_monitor_mono"); */ } - void BasicUI::quick_snapshot_stay () { access_action("Main/QuickSnapshotStay"); } void BasicUI::quick_snapshot_switch () { access_action("Main/QuickSnapshotSwitch"); } @@ -401,30 +535,69 @@ BasicUI::locked () return session->transport_locked (); } -ARDOUR::framecnt_t +ARDOUR::samplecnt_t BasicUI::timecode_frames_per_hour () { return session->timecode_frames_per_hour (); } void -BasicUI::timecode_time (framepos_t where, Timecode::Time& timecode) +BasicUI::timecode_time (samplepos_t where, Timecode::Time& timecode) { session->timecode_time (where, *((Timecode::Time *) &timecode)); } void -BasicUI::timecode_to_sample (Timecode::Time& timecode, framepos_t & sample, bool use_offset, bool use_subframes) const +BasicUI::timecode_to_sample (Timecode::Time& timecode, samplepos_t & sample, bool use_offset, bool use_subframes) const { session->timecode_to_sample (*((Timecode::Time*)&timecode), sample, use_offset, use_subframes); } void -BasicUI::sample_to_timecode (framepos_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes) const +BasicUI::sample_to_timecode (samplepos_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes) const { session->sample_to_timecode (sample, *((Timecode::Time*)&timecode), use_offset, use_subframes); } +void +BasicUI::cancel_all_solo () +{ + if (session) { + session->cancel_all_solo (); + } +} + +struct SortLocationsByPosition { + bool operator() (Location* a, Location* b) { + return a->start() < b->start(); + } +}; + +void +BasicUI::goto_nth_marker (int n) +{ + if (!session) { + return; + } + + const Locations::LocationList& l (session->locations()->list()); + Locations::LocationList ordered; + ordered = l; + + SortLocationsByPosition cmp; + ordered.sort (cmp); + + for (Locations::LocationList::iterator i = ordered.begin(); n >= 0 && i != ordered.end(); ++i) { + if ((*i)->is_mark() && !(*i)->is_hidden() && !(*i)->is_session_range()) { + if (n == 0) { + session->request_locate ((*i)->start(), session->transport_rolling()); + break; + } + --n; + } + } +} + #if 0 this stuff is waiting to go in so that all UIs can offer complex solo/mute functionality