X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fsurfaces%2Fcontrol_protocol%2Fbasic_ui.cc;h=74c2802a7aa15856bedd91d583f073c2b41cb2af;hb=cf52d6e4b40111eb04b244ec054055a4ec15dbe0;hp=8c3eb029823d18a6d7bbad71b2aaff6caff73c8c;hpb=aae367b63c9b619db1e40f27dc334c6987219481;p=ardour.git diff --git a/libs/surfaces/control_protocol/basic_ui.cc b/libs/surfaces/control_protocol/basic_ui.cc index 8c3eb02982..74c2802a7a 100644 --- a/libs/surfaces/control_protocol/basic_ui.cc +++ b/libs/surfaces/control_protocol/basic_ui.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2006 Paul Davis + Copyright (C) 2006 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser @@ -19,16 +19,17 @@ */ #include "pbd/pthread_utils.h" +#include "pbd/memento_command.h" #include "ardour/session.h" #include "ardour/location.h" +#include "ardour/tempo.h" #include "control_protocol/basic_ui.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace ARDOUR; -using ARDOUR::nframes_t; PBD::Signal2 BasicUI::AccessAction; @@ -44,7 +45,7 @@ BasicUI::BasicUI () BasicUI::~BasicUI () { - + } void @@ -57,7 +58,7 @@ BasicUI::register_thread (std::string name) } void -BasicUI::access_action ( std::string action_path ) +BasicUI::access_action ( std::string action_path ) { int split_at = action_path.find( "/" ); std::string group = action_path.substr( 0, split_at ); @@ -67,16 +68,55 @@ BasicUI::access_action ( std::string action_path ) } void -BasicUI::loop_toggle () +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) +{ + Location* tll; + if ((tll = session->locations()->auto_loop_location()) == 0) { + Location* loc = new Location (*session, start, end, _("Loop"), Location::IsAutoLoop); + session->locations()->add (loc, true); + session->set_auto_loop_location (loc); + } else { + tll->set_hidden (false, this); + tll->set (start, end); + } } void @@ -85,29 +125,69 @@ BasicUI::goto_start () session->goto_start (); } +void +BasicUI::goto_zero () +{ + session->request_locate (0); +} + void BasicUI::goto_end () { session->goto_end (); } -void -BasicUI::add_marker () +void +BasicUI::add_marker (const std::string& markername) { - nframes_t when = session->audible_frame(); - session->locations()->add (new Location (when, when, _("unnamed"), Location::IsMark)); + framepos_t where = session->audible_frame(); + Location *location = new Location (*session, where, where, markername, Location::IsMark); + session->begin_reversible_command (_("add marker")); + XMLNode &before = session->locations()->get_state(); + session->locations()->add (location, true); + XMLNode &after = session->locations()->get_state(); + session->add_command (new MementoCommand(*(session->locations()), &before, &after)); + session->commit_reversible_command (); +} + +void +BasicUI::remove_marker_at_playhead () +{ + if (session) { + //set up for undo + XMLNode &before = session->locations()->get_state(); + bool removed = false; + + //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)); + for (Locations::LocationList::iterator i = locs.begin(); i != locs.end(); ++i) { + if ((*i)->is_mark()) { + session->locations()->remove (*i); + removed = true; + } + } + + //store undo + if (removed) { + session->begin_reversible_command (_("remove marker")); + XMLNode &after = session->locations()->get_state(); + session->add_command(new MementoCommand(*(session->locations()), &before, &after)); + session->commit_reversible_command (); + } + } } void BasicUI::rewind () { - session->request_transport_speed (-2.0f); + session->request_transport_speed (session->transport_speed() - 1.5); } void BasicUI::ffwd () { - session->request_transport_speed (2.0f); + session->request_transport_speed (session->transport_speed() + 1.5); } void @@ -119,22 +199,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 (false); +#if 0 + if (session->config.get_external_sync()) { + switch (Config->get_sync_source()) { + case Engine: + break; + default: + /* transport controlled by the master */ + return; + } } - - if (from_last_start && rolling) { - session->request_locate (session->last_transport_start(), true); +#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 (!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 @@ -152,10 +266,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 () { @@ -165,10 +291,10 @@ BasicUI::save_state () void BasicUI::prev_marker () { - Location *location = session->locations()->first_location_before (session->transport_frame()); - - if (location) { - session->request_locate (location->start(), session->transport_rolling()); + framepos_t pos = session->locations()->first_mark_before (session->transport_frame()); + + if (pos >= 0) { + session->request_locate (pos, session->transport_rolling()); } else { session->goto_start (); } @@ -177,12 +303,12 @@ BasicUI::prev_marker () void BasicUI::next_marker () { - Location *location = session->locations()->first_location_after (session->transport_frame()); + framepos_t pos = session->locations()->first_mark_after (session->transport_frame()); - if (location) { - session->request_locate (location->start(), session->transport_rolling()); + if (pos >= 0) { + session->request_locate (pos, session->transport_rolling()); } else { - session->request_locate (session->current_end_frame()); + session->goto_end(); } } @@ -248,18 +374,91 @@ BasicUI::set_record_enable (bool yn) } } -nframes_t +framepos_t BasicUI::transport_frame () { return session->transport_frame(); } void -BasicUI::locate (nframes_t where, bool roll_after_locate) +BasicUI::locate (framepos_t where, bool roll_after_locate) { session->request_locate (where, 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(); + + s+= secs; + if (s < 0) current = 0; + s = s * session->nominal_frame_rate(); + + session->request_locate ( floor(s) ); +} + +void +BasicUI::jump_by_bars (double bars) +{ + TempoMap& tmap (session->tempo_map()); + Timecode::BBT_Time bbt (tmap.bbt_at_frame (session->transport_frame())); + + bars += bbt.bars; + if (bars < 0) bars = 0; + + AnyTime any; + any.type = AnyTime::BBT; + any.bbt.bars = bars; + + session->request_locate ( session->convert_to_frames (any) ); +} + +void BasicUI::mark_in () { access_action("Editor/start-range-from-playhead"); } +void BasicUI::mark_out () { access_action("Editor/finish-range-from-playhead"); } + +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::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"); } + +void BasicUI::fit_1_track() { access_action("Editor/fit_1_track"); } +void BasicUI::fit_2_tracks() { access_action("Editor/fit_2_tracks"); } +void BasicUI::fit_4_tracks() { access_action("Editor/fit_4_tracks"); } +void BasicUI::fit_8_tracks() { access_action("Editor/fit_8_tracks"); } +void BasicUI::fit_16_tracks() { access_action("Editor/fit_16_tracks"); } +void BasicUI::fit_32_tracks() { access_action("Editor/fit_32_tracks"); } +void BasicUI::fit_all_tracks() { access_action("Editor/fit_all_tracks"); } + +void BasicUI::zoom_10_ms() { access_action("Editor/zoom_10_ms"); } +void BasicUI::zoom_100_ms() { access_action("Editor/zoom_100_ms"); } +void BasicUI::zoom_1_sec() { access_action("Editor/zoom_1_sec"); } +void BasicUI::zoom_10_sec() { access_action("Editor/zoom_10_sec"); } +void BasicUI::zoom_1_min() { access_action("Editor/zoom_1_min"); } +void BasicUI::zoom_5_min() { access_action("Editor/zoom_5_min"); } +void BasicUI::zoom_10_min() { access_action("Editor/zoom_10_min"); } +void BasicUI::zoom_to_session() { access_action("Editor/zoom-to-session"); } +void BasicUI::temporal_zoom_in() { access_action("Editor/temporal-zoom-in"); } +void BasicUI::temporal_zoom_out() { access_action("Editor/temporal-zoom-out"); } + +void BasicUI::scroll_up_1_track() { access_action("Editor/step-tracks-up"); } +void BasicUI::scroll_dn_1_track() { access_action("Editor/step-tracks-down"); } +void BasicUI::scroll_up_1_page() { access_action("Editor/scroll-tracks-up"); } +void BasicUI::scroll_dn_1_page() { access_action("Editor/scroll-tracks-down"); } + + bool BasicUI::locating () { @@ -272,27 +471,122 @@ BasicUI::locked () return session->transport_locked (); } -nframes_t +ARDOUR::framecnt_t BasicUI::timecode_frames_per_hour () { return session->timecode_frames_per_hour (); } void -BasicUI::timecode_time (nframes_t where, Timecode::Time& timecode) +BasicUI::timecode_time (framepos_t where, Timecode::Time& timecode) { session->timecode_time (where, *((Timecode::Time *) &timecode)); } -void -BasicUI::timecode_to_sample (Timecode::Time& timecode, nframes_t& sample, bool use_offset, bool use_subframes) const +void +BasicUI::timecode_to_sample (Timecode::Time& timecode, framepos_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 (nframes_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes) const +void +BasicUI::sample_to_timecode (framepos_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes) const { session->sample_to_timecode (sample, *((Timecode::Time*)&timecode), use_offset, use_subframes); } +#if 0 +this stuff is waiting to go in so that all UIs can offer complex solo/mute functionality + +void +BasicUI::solo_release (boost::shared_ptr r) +{ +} + +void +BasicUI::solo_press (boost::shared_ptr r, bool momentary, bool global, bool exclusive, bool isolate, bool solo_group) +{ + if (momentary) { + _solo_release = new SoloMuteRelease (_route->soloed()); + } + + if (global) { + + if (_solo_release) { + _solo_release->routes = _session->get_routes (); + } + + if (Config->get_solo_control_is_listen_control()) { + _session->set_listen (_session->get_routes(), !_route->listening(), Session::rt_cleanup, true); + } else { + _session->set_solo (_session->get_routes(), !_route->soloed(), Session::rt_cleanup, true); + } + + } else if (exclusive) { + + if (_solo_release) { + _solo_release->exclusive = true; + + boost::shared_ptr routes = _session->get_routes(); + + for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) { + if ((*i)->soloed ()) { + _solo_release->routes_on->push_back (*i); + } else { + _solo_release->routes_off->push_back (*i); + } + } + } + + if (Config->get_solo_control_is_listen_control()) { + /* ??? we need a just_one_listen() method */ + } else { + _session->set_just_one_solo (_route, true); + } + + } else if (isolate) { + + // shift-click: toggle solo isolated status + + _route->set_solo_isolated (!_route->solo_isolated(), this); + delete _solo_release; + _solo_release = 0; + + } else if (solo_group) { + + /* Primary-button1: solo mix group. + NOTE: Primary-button2 is MIDI learn. + */ + + if (_route->route_group()) { + + if (_solo_release) { + _solo_release->routes = _route->route_group()->route_list(); + } + + if (Config->get_solo_control_is_listen_control()) { + _session->set_listen (_route->route_group()->route_list(), !_route->listening(), Session::rt_cleanup, true); + } else { + _session->set_solo (_route->route_group()->route_list(), !_route->soloed(), Session::rt_cleanup, true); + } + } + + } else { + + /* click: solo this route */ + + boost::shared_ptr rl (new RouteList); + rl->push_back (route()); + + if (_solo_release) { + _solo_release->routes = rl; + } + + if (Config->get_solo_control_is_listen_control()) { + _session->set_listen (rl, !_route->listening()); + } else { + _session->set_solo (rl, !_route->soloed()); + } + } +} +#endif