fix CPI window handling:

Move control-surface editor-window management to the control surface.
The Preferences-Dialog is not aware of session specific or surface
specific actions and cannot properly manage the window.
This commit is contained in:
Robin Gareus 2014-09-13 16:59:02 +02:00
parent 009ced9640
commit d8e64103a6
4 changed files with 57 additions and 34 deletions

View File

@ -25,8 +25,10 @@
#include "ardour/audioengine.h"
#include "ardour/automation_watch.h"
#include "ardour/control_protocol_manager.h"
#include "ardour/profile.h"
#include "ardour/session.h"
#include "control_protocol/control_protocol.h"
#include "actions.h"
#include "add_route_dialog.h"
@ -262,6 +264,16 @@ ARDOUR_UI::unload_session (bool hide_stuff)
}
}
{
// tear down session specific CPI (owned by rc_config_editor which can remain)
ControlProtocolManager& m = ControlProtocolManager::instance ();
for (std::list<ControlProtocolInfo*>::iterator i = m.control_protocol_info.begin(); i != m.control_protocol_info.end(); ++i) {
if (*i && (*i)->protocol && (*i)->protocol->has_editor ()) {
(*i)->protocol->tear_down_gui ();
}
}
}
if (hide_stuff) {
editor->hide ();
mixer->hide ();

View File

@ -795,17 +795,7 @@ private:
if (!was_enabled) {
ControlProtocolManager::instance().activate (*cpi);
} else {
Gtk::Window* win = r[_model.editor];
if (win) {
win->hide ();
}
ControlProtocolManager::instance().deactivate (*cpi);
if (win) {
delete win;
r[_model.editor] = 0;
}
}
}
@ -817,8 +807,8 @@ private:
}
}
void edit_clicked (GdkEventButton* ev)
{
void edit_clicked (GdkEventButton* ev)
{
if (ev->type != GDK_2BUTTON_PRESS) {
return;
}
@ -828,26 +818,32 @@ private:
TreeModel::Row row;
row = *(_view.get_selection()->get_selected());
Window* win = row[_model.editor];
if (win && !win->is_visible()) {
win->present ();
} else {
cpi = row[_model.protocol_info];
if (cpi && cpi->protocol && cpi->protocol->has_editor ()) {
Box* box = (Box*) cpi->protocol->get_gui ();
if (box) {
string title = row[_model.name];
ArdourWindow* win = new ArdourWindow (_parent, title);
win->set_title ("Control Protocol Options");
win->add (*box);
box->show ();
win->present ();
row[_model.editor] = win;
}
}
if (!row[_model.enabled]) {
return;
}
cpi = row[_model.protocol_info];
if (!cpi || !cpi->protocol || !cpi->protocol->has_editor ()) {
return;
}
Box* box = (Box*) cpi->protocol->get_gui ();
if (!box) {
return;
}
if (box->get_parent()) {
static_cast<ArdourWindow*>(box->get_parent())->present();
return;
}
string title = row[_model.name];
/* once created, the window is managed by the surface itself (as ->get_parent())
* Surface's tear_down_gui() is called on session close, when de-activating
* or re-initializing a surface.
* tear_down_gui() hides an deletes the Window if it exists.
*/
ArdourWindow* win = new ArdourWindow (_parent, title);
win->set_title ("Control Protocol Options");
win->add (*box);
box->show ();
win->present ();
}
class ControlSurfacesModelColumns : public TreeModelColumnRecord
@ -860,14 +856,12 @@ private:
add (enabled);
add (feedback);
add (protocol_info);
add (editor);
}
TreeModelColumn<string> name;
TreeModelColumn<bool> enabled;
TreeModelColumn<bool> feedback;
TreeModelColumn<ControlProtocolInfo*> protocol_info;
TreeModelColumn<Gtk::Window*> editor;
};
Glib::RefPtr<ListStore> _store;

View File

@ -68,13 +68,22 @@ GenericMidiControlProtocol::get_gui () const
if (!gui) {
const_cast<GenericMidiControlProtocol*>(this)->build_gui ();
}
static_cast<Gtk::VBox*>(gui)->show_all();
return gui;
}
void
GenericMidiControlProtocol::tear_down_gui ()
{
if (gui) {
Gtk::Widget *w = static_cast<Gtk::VBox*>(gui)->get_parent();
if (w) {
w->hide();
delete w;
}
}
delete (GMCPGUI*) gui;
gui = 0;
}
void

View File

@ -51,14 +51,22 @@ MackieControlProtocol::get_gui () const
if (!_gui) {
const_cast<MackieControlProtocol*>(this)->build_gui ();
}
static_cast<Gtk::Notebook*>(_gui)->show_all();
return _gui;
}
void
MackieControlProtocol::tear_down_gui ()
{
if (_gui) {
Gtk::Widget *w = static_cast<Gtk::Widget*>(_gui)->get_parent();
if (w) {
w->hide();
delete w;
}
}
delete (MackieControlProtocolGUI*) _gui;
_gui = 0;
}
void