along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id$
*/
#include <gtkmm2ext/gtk_ui.h>
#include <ardour/route_group.h>
#include <pbd/memento_command.h>
+#include <pbd/stacktrace.h>
+#include <pbd/shiva.h>
#include "route_ui.h"
#include "keyboard.h"
#include "gui_thread.h"
#include <ardour/route.h>
+#include <ardour/session.h>
+#include <ardour/audioengine.h>
#include <ardour/audio_track.h>
#include <ardour/audio_diskstream.h>
using namespace ARDOUR;
using namespace PBD;
+RouteUI::RouteUI (ARDOUR::Session& sess, const char* mute_name, const char* solo_name, const char* rec_name)
+ : AxisView(sess)
+{
+ init ();
+ set_button_names (mute_name, solo_name, rec_name);
+}
-RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session& sess, const char* m_name,
- const char* s_name, const char* r_name)
- : AxisView(sess),
- _route(rt),
- mute_button(0),
- solo_button(0),
- rec_enable_button(0)
+RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt,
+ ARDOUR::Session& sess, const char* mute_name, const char* solo_name, const char* rec_name)
+ : AxisView(sess)
+{
+ init ();
+ set_button_names (mute_name, solo_name, rec_name);
+ set_route (rt);
+}
+
+void
+RouteUI::init ()
{
xml_node = 0;
mute_menu = 0;
ignore_toggle = false;
wait_for_release = false;
route_active_menu_item = 0;
+ was_solo_safe = false;
+ polarity_menu_item = 0;
+ denormal_menu_item = 0;
+
+ mute_button = manage (new BindableToggleButton (0, ""));
+ mute_button->set_self_managed (true);
+ mute_button->set_name ("MuteButton");
+
+ solo_button = manage (new BindableToggleButton (0, ""));
+ solo_button->set_self_managed (true);
+ solo_button->set_name ("SoloButton");
+
+ rec_enable_button = manage (new BindableToggleButton (0, ""));
+ rec_enable_button->set_name ("RecordEnableButton");
+ rec_enable_button->set_self_managed (true);
+
+ _session.SoloChanged.connect (mem_fun(*this, &RouteUI::solo_changed_so_update_mute));
+}
+
+void
+RouteUI::reset ()
+{
+ connections.clear ();
+
+ if (solo_menu) {
+ delete solo_menu;
+ solo_menu = 0;
+ }
+
+ if (mute_menu) {
+ delete mute_menu;
+ mute_menu = 0;
+ }
+
+ if (remote_control_menu) {
+ delete remote_control_menu;
+ remote_control_menu = 0;
+ }
+
+ if (xml_node) {
+ /* do not delete the node - its owned by the route */
+ xml_node = 0;
+ }
+
+ route_active_menu_item = 0;
+ polarity_menu_item = 0;
+ denormal_menu_item = 0;
+}
+
+void
+RouteUI::set_button_names (const char* mute, const char* solo, const char* rec)
+{
+ m_name = mute;
+ s_name = solo;
+ r_name = rec;
+}
+
+void
+RouteUI::set_route (boost::shared_ptr<Route> rp)
+{
+ reset ();
+
+ _route = rp;
if (set_color_from_route()) {
set_color (unique_random_color());
}
- _route->GoingAway.connect (mem_fun (*this, &RouteUI::route_removed));
- _route->active_changed.connect (mem_fun (*this, &RouteUI::route_active_changed));
+ /* no, there is no memory leak here. This object cleans itself (and other stuff)
+ up when the route is destroyed.
+ */
+
+ new PairedShiva<Route,RouteUI> (*_route, *this);
- mute_button = manage (new BindableToggleButton (_route->mute_control(), m_name ));
- solo_button = manage (new BindableToggleButton (_route->solo_control(), s_name ));
+ mute_button->set_controllable (&_route->mute_control());
+ mute_button->set_label (m_name);
+ solo_button->set_controllable (&_route->solo_control());
+ solo_button->set_label (s_name);
+
+ connections.push_back (_route->active_changed.connect (mem_fun (*this, &RouteUI::route_active_changed)));
+ connections.push_back (_route->mute_changed.connect (mem_fun(*this, &RouteUI::mute_changed)));
+ connections.push_back (_route->solo_changed.connect (mem_fun(*this, &RouteUI::solo_changed)));
+ connections.push_back (_route->solo_safe_changed.connect (mem_fun(*this, &RouteUI::solo_changed)));
+
+ /* when solo changes, update mute state too, in case the user wants us to display it */
+
+ update_solo_display ();
+ update_mute_display ();
+
if (is_track()) {
boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track>(_route);
- t->diskstream().RecordEnableChanged.connect (mem_fun (*this, &RouteUI::route_rec_enable_changed));
+ connections.push_back (t->diskstream()->RecordEnableChanged.connect (mem_fun (*this, &RouteUI::route_rec_enable_changed)));
- _session.RecordStateChanged.connect (mem_fun (*this, &RouteUI::session_rec_enable_changed));
+ connections.push_back (_session.RecordStateChanged.connect (mem_fun (*this, &RouteUI::session_rec_enable_changed)));
- rec_enable_button = manage (new BindableToggleButton (t->rec_enable_control(), r_name ));
+ rec_enable_button->set_controllable (&t->rec_enable_control());
+ rec_enable_button->set_label (r_name);
- rec_enable_button->unset_flags (Gtk::CAN_FOCUS);
-
update_rec_display ();
}
- mute_button->unset_flags (Gtk::CAN_FOCUS);
- solo_button->unset_flags (Gtk::CAN_FOCUS);
+ connections.push_back (_route->RemoteControlIDChanged.connect (mem_fun(*this, &RouteUI::refresh_remote_control_menu)));
/* map the current state */
RouteUI::~RouteUI()
{
- delete mute_menu;
+ GoingAway (); /* EMIT SIGNAL */
+ if (solo_menu) {
+ delete solo_menu;
+ }
+
+ if (mute_menu) {
+ delete mute_menu;
+ }
+
+ if (remote_control_menu) {
+ delete remote_control_menu;
+ }
}
-gint
+bool
RouteUI::mute_press(GdkEventButton* ev)
{
+ if (ev->type == GDK_2BUTTON_PRESS) {
+ return true;
+ }
+
if (!ignore_toggle) {
if (Keyboard::is_context_menu_event (ev)) {
build_mute_menu();
}
- mute_menu->popup(0,0);
+ mute_menu->popup(0,ev->time);
} else {
if (ev->button == 2) {
- // ctrl-button2 click is the midi binding click
+ // Primary-button2 click is the midi binding click
// button2-click is "momentary"
- if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control))) {
+ if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier))) {
wait_for_release = true;
+ } else {
+ return false;
}
}
if (ev->button == 1 || ev->button == 2) {
- if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Shift))) {
+ if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
- /* ctrl-shift-click applies change to all routes */
+ /* Primary-Tertiary-click applies change to all routes */
_session.begin_reversible_command (_("mute change"));
Session::GlobalMuteStateCommand *cmd = new Session::GlobalMuteStateCommand(_session, this);
_session.add_command(cmd);
_session.commit_reversible_command ();
- } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
+ } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
- /* ctrl-click applies change to the mix group.
- ctrl-button2 is MIDI learn.
+ /* Primary-button1 applies change to the mix group.
+ NOTE: Primary-button2 is MIDI learn.
*/
if (ev->button == 1) {
return true;
}
-gint
+bool
RouteUI::mute_release(GdkEventButton* ev)
{
if (!ignore_toggle) {
return true;
}
-gint
+bool
RouteUI::solo_press(GdkEventButton* ev)
{
+ /* ignore double clicks */
+
+ if (ev->type == GDK_2BUTTON_PRESS) {
+ return true;
+ }
+
if (!ignore_toggle) {
if (Keyboard::is_context_menu_event (ev)) {
build_solo_menu ();
}
- solo_menu->popup (1, 0);
+ solo_menu->popup (1, ev->time);
} else {
if (ev->button == 2) {
- // ctrl-button2 click is the midi binding click
+ // Primary-button2 click is the midi binding click
// button2-click is "momentary"
- if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control))) {
+ if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier))) {
wait_for_release = true;
+ } else {
+ return false;
}
}
if (ev->button == 1 || ev->button == 2) {
- if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Shift))) {
+ if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
- /* ctrl-shift-click applies change to all routes */
+ /* Primary-Tertiary-click applies change to all routes */
_session.begin_reversible_command (_("solo change"));
Session::GlobalSoloStateCommand *cmd = new Session::GlobalSoloStateCommand(_session, this);
_session.add_command (cmd);
_session.commit_reversible_command ();
- } else if (Keyboard::modifier_state_contains (ev->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Alt))) {
+ } else if (Keyboard::modifier_state_contains (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::SecondaryModifier))) {
- // ctrl-alt-click: exclusively solo this track, not a toggle */
+ // Primary-Secondary-click: exclusively solo this track, not a toggle */
_session.begin_reversible_command (_("solo change"));
Session::GlobalSoloStateCommand *cmd = new Session::GlobalSoloStateCommand (_session, this);
_session.add_command(cmd);
_session.commit_reversible_command ();
- } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Shift)) {
+ } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
// shift-click: set this route to solo safe
_route->set_solo_safe (!_route->solo_safe(), this);
wait_for_release = false;
- } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
+ } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
- /* ctrl-click: solo mix group.
- ctrl-button2 is MIDI learn.
+ /* Primary-button1: solo mix group.
+ NOTE: Primary-button2 is MIDI learn.
*/
if (ev->button == 1) {
} else {
/* click: solo this route */
-
reversibly_apply_route_boolean ("solo change", &Route::set_solo, !_route->soloed(), this);
}
}
return true;
}
-gint
+bool
RouteUI::solo_release(GdkEventButton* ev)
{
if (!ignore_toggle) {
return true;
}
-gint
+bool
RouteUI::rec_enable_press(GdkEventButton* ev)
{
+ if (ev->type == GDK_2BUTTON_PRESS) {
+ return true;
+ }
+
+ if (!_session.engine().connected()) {
+ MessageDialog msg (_("Not connected to JACK - cannot engage record"));
+ msg.run ();
+ return true;
+ }
+
if (!ignore_toggle && is_track() && rec_enable_button) {
- if (ev->button == 2 && Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
+ if (ev->button == 2 && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
+
// do nothing on midi bind event
- }
- else if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Shift))) {
+ return false;
+
+ } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
_session.begin_reversible_command (_("rec-enable change"));
Session::GlobalRecordEnableStateCommand *cmd = new Session::GlobalRecordEnableStateCommand(_session, this);
_session.add_command(cmd);
_session.commit_reversible_command ();
- } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
+ } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
+
+ /* Primary-button1 applies change to the mix group.
+ NOTE: Primary-button2 is MIDI learn.
+ */
set_mix_group_rec_enable (_route, !_route->record_enabled());
} else {
reversibly_apply_audio_track_boolean ("rec-enable change", &AudioTrack::set_record_enable, !audio_track()->record_enabled(), this);
-
- ignore_toggle = true;
- rec_enable_button->set_active(audio_track()->record_enabled());
- ignore_toggle = false;
}
-
- stop_signal (*rec_enable_button, "button-press-event");
}
- return TRUE;
+ return true;
+}
+
+bool
+RouteUI::rec_enable_release (GdkEventButton* ev)
+{
+ return true;
}
void
RouteUI::update_solo_display ()
{
bool x;
-
+ vector<Gdk::Color> fg_colors;
+ Gdk::Color c;
+
if (solo_button->get_active() != (x = _route->soloed())){
ignore_toggle = true;
solo_button->set_active(x);
ignore_toggle = false;
- }
+ }
- /* show solo safe */
-
- if (_route->solo_safe()){
- solo_button->set_name(safe_solo_button_name());
+ if (_route->solo_safe()) {
+ solo_button->set_visual_state (2);
+ } else if (_route->soloed()) {
+ solo_button->set_visual_state (1);
} else {
- solo_button->set_name(solo_button_name());
+ solo_button->set_visual_state (0);
}
}
+void
+RouteUI::solo_changed_so_update_mute ()
+{
+ Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_mute_display));
+}
+
void
RouteUI::mute_changed(void* src)
{
void
RouteUI::update_mute_display ()
{
- bool x;
+ bool model = _route->muted();
+ bool view = mute_button->get_active();
+
+ /* first make sure the button's "depressed" visual
+ is correct.
+ */
- if (mute_button->get_active() != (x = _route->muted())){
+ if (model != view) {
ignore_toggle = true;
- mute_button->set_active(x);
+ mute_button->set_active (model);
ignore_toggle = false;
}
+
+ /* now attend to visual state */
+
+ if (Config->get_show_solo_mutes()) {
+ if (_route->muted()) {
+ mute_button->set_visual_state (2);
+ } else if (!_route->soloed() && _route->solo_muted()) {
+
+ mute_button->set_visual_state (1);
+ } else {
+ mute_button->set_visual_state (0);
+ }
+ } else {
+ if (_route->muted()) {
+ mute_button->set_visual_state (2);
+ } else {
+ mute_button->set_visual_state (0);
+ }
+ }
+
}
void
/* first make sure the button's "depressed" visual
is correct.
*/
-
+
if (model != view) {
ignore_toggle = true;
rec_enable_button->set_active (model);
if (model) {
switch (_session.record_status ()) {
+ case Session::Recording:
+ rec_enable_button->set_visual_state (1);
+ break;
+
case Session::Disabled:
case Session::Enabled:
- if (rec_enable_button->get_state() != Gtk::STATE_ACTIVE) {
- rec_enable_button->set_state (Gtk::STATE_ACTIVE);
- }
+ rec_enable_button->set_visual_state (2);
break;
- case Session::Recording:
- if (rec_enable_button->get_state() != Gtk::STATE_SELECTED) {
- rec_enable_button->set_state (Gtk::STATE_SELECTED);
- }
- break;
}
} else {
- if (rec_enable_button->get_state() != Gtk::STATE_NORMAL) {
- rec_enable_button->set_state (Gtk::STATE_NORMAL);
- }
+ rec_enable_button->set_visual_state (0);
}
}
void
RouteUI::build_remote_control_menu ()
{
- remote_control_menu = manage (new Menu);
+ remote_control_menu = new Menu;
refresh_remote_control_menu ();
}
void
RouteUI::refresh_remote_control_menu ()
{
+ ENSURE_GUI_THREAD (mem_fun (*this, &RouteUI::refresh_remote_control_menu));
+
+ // only refresh the menu if it has been instantiated
+
+ if (remote_control_menu == 0) {
+ return;
+ }
+
using namespace Menu_Helpers;
RadioMenuItem::Group rc_group;
CheckMenuItem* rc_active;
- uint32_t limit = _session.ntracks();
+ uint32_t limit = _session.ntracks() + _session.nbusses();
char buf[32];
MenuList& rc_items = remote_control_menu->items();
items.push_back (CheckMenuElem(*check));
check->show_all();
- items.push_back (SeparatorElem());
+ //items.push_back (SeparatorElem());
// items.push_back (MenuElem (_("MIDI Bind"), mem_fun (*mute_button, &BindableToggleButton::midi_learn)));
}
items.push_back (CheckMenuElem(*check));
check->show_all();
- items.push_back (SeparatorElem());
+ //items.push_back (SeparatorElem());
// items.push_back (MenuElem (_("MIDI Bind"), mem_fun (*mute_button, &BindableToggleButton::midi_learn)));
}
XMLNode &before = _route->get_state();
bind(mem_fun(*_route, func), yn, arg)();
XMLNode &after = _route->get_state();
- _session.add_command (new MementoCommand<Route>(*_route, before, after));
+ _session.add_command (new MementoCommand<Route>(*_route, &before, &after));
_session.commit_reversible_command ();
}
XMLNode &before = audio_track()->get_state();
bind (mem_fun (*audio_track(), func), yn, arg)();
XMLNode &after = audio_track()->get_state();
- _session.add_command (new MementoCommand<AudioTrack>(*audio_track(), before, after));
+ _session.add_command (new MementoCommand<AudioTrack>(*audio_track(), &before, &after));
_session.commit_reversible_command ();
}
snprintf (buf, sizeof (buf), "%d:%d:%d", c.get_red(), c.get_green(), c.get_blue());
xml_node->add_property ("color", buf);
- _route->gui_changed ("color", (void *) 0); /* EMIT_SIGNAL */
+ _route->gui_changed ("color", (void *) 0); /* EMIT_SIGNAL */
}
return FALSE;
}
-void
-RouteUI::route_removed ()
-{
- ENSURE_GUI_THREAD(mem_fun (*this, &RouteUI::route_removed));
-
- delete this;
-}
-
void
RouteUI::route_rename ()
{
/* no signal for this yet */
}
+void
+RouteUI::toggle_denormal_protection ()
+{
+ if (denormal_menu_item) {
+
+ bool x;
+
+ ENSURE_GUI_THREAD(mem_fun (*this, &RouteUI::toggle_denormal_protection));
+
+ if ((x = denormal_menu_item->get_active()) != _route->denormal_protection()) {
+ _route->set_denormal_protection (x, this);
+ }
+ }
+}
+
+void
+RouteUI::denormal_protection_changed ()
+{
+ /* no signal for this yet */
+}
+
+
void
RouteUI::solo_safe_toggle(void* src, Gtk::CheckMenuItem* check)
{
bool
RouteUI::is_track () const
{
- return dynamic_cast<Track*>(_route.get()) != 0;
+ return boost::dynamic_pointer_cast<Track>(_route) != 0;
}
-Track*
+boost::shared_ptr<Track>
RouteUI::track() const
{
- return dynamic_cast<Track*>(_route.get());
+ return boost::dynamic_pointer_cast<Track>(_route);
}
bool
RouteUI::is_audio_track () const
{
- return dynamic_cast<AudioTrack*>(_route.get()) != 0;
+ return boost::dynamic_pointer_cast<AudioTrack>(_route) != 0;
}
-AudioTrack*
+boost::shared_ptr<AudioTrack>
RouteUI::audio_track() const
{
- return dynamic_cast<AudioTrack*>(_route.get());
+ return boost::dynamic_pointer_cast<AudioTrack>(_route);
}
-Diskstream*
+boost::shared_ptr<Diskstream>
RouteUI::get_diskstream () const
{
boost::shared_ptr<Track> t;
if ((t = boost::dynamic_pointer_cast<Track>(_route)) != 0) {
- return &t->diskstream();
+ return t->diskstream();
} else {
- return 0;
+ return boost::shared_ptr<Diskstream> ((Diskstream*) 0);
}
}