summaryrefslogtreecommitdiffstats
path: root/src/progs/ingenuity/WindowFactory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/progs/ingenuity/WindowFactory.cpp')
-rw-r--r--src/progs/ingenuity/WindowFactory.cpp232
1 files changed, 210 insertions, 22 deletions
diff --git a/src/progs/ingenuity/WindowFactory.cpp b/src/progs/ingenuity/WindowFactory.cpp
index c7d79aca..3edbf568 100644
--- a/src/progs/ingenuity/WindowFactory.cpp
+++ b/src/progs/ingenuity/WindowFactory.cpp
@@ -15,13 +15,70 @@
*/
#include "WindowFactory.h"
+#include "App.h"
#include "PatchWindow.h"
#include "GladeFactory.h"
-#include "App.h"
+#include "NodePropertiesWindow.h"
+#include "PatchPropertiesWindow.h"
+#include "NodeControlWindow.h"
+#include "LoadPluginWindow.h"
+#include "LoadPatchWindow.h"
+#include "LoadSubpatchWindow.h"
+#include "RenameWindow.h"
+#include "NewSubpatchWindow.h"
namespace Ingenuity {
+WindowFactory::WindowFactory()
+: _load_plugin_win(NULL)
+, _load_patch_win(NULL)
+, _new_subpatch_win(NULL)
+, _load_subpatch_win(NULL)
+, _node_properties_win(NULL)
+, _patch_properties_win(NULL)
+{
+ Glib::RefPtr<Gnome::Glade::Xml> xml = GladeFactory::new_glade_reference();
+
+ xml->get_widget_derived("load_plugin_win", _load_plugin_win);
+ xml->get_widget_derived("load_patch_win", _load_patch_win);
+ xml->get_widget_derived("new_subpatch_win", _new_subpatch_win);
+ xml->get_widget_derived("load_subpatch_win", _load_subpatch_win);
+ xml->get_widget_derived("node_properties_win", _node_properties_win);
+ xml->get_widget_derived("patch_properties_win", _patch_properties_win);
+
+}
+
+
+WindowFactory::~WindowFactory()
+{
+ for (PatchWindowMap::iterator i = _patch_windows.begin(); i != _patch_windows.end(); ++i)
+ delete i->second;
+
+ for (ControlWindowMap::iterator i = _control_windows.begin(); i != _control_windows.end(); ++i)
+ delete i->second;
+
+}
+
+
+PatchWindow*
+WindowFactory::patch_window(CountedPtr<PatchModel> patch)
+{
+ PatchWindowMap::iterator w = _patch_windows.find(patch->path());
+
+ return (w == _patch_windows.end()) ? NULL : w->second;
+}
+
+
+NodeControlWindow*
+WindowFactory::control_window(CountedPtr<NodeModel> node)
+{
+ ControlWindowMap::iterator w = _control_windows.find(node->path());
+
+ return (w == _control_windows.end()) ? NULL : w->second;
+}
+
+
/** Present a PatchWindow for a Patch.
*
* If @a preferred is not NULL, it will be set to display @a patch if the patch
@@ -29,54 +86,55 @@ namespace Ingenuity {
* @a preferred left unmodified.
*/
void
-WindowFactory::present(CountedPtr<PatchController> patch, PatchWindow* preferred)
+WindowFactory::present_patch(CountedPtr<PatchModel> patch, PatchWindow* preferred, CountedPtr<PatchView> view)
{
- std::map<Path, PatchWindow*>::iterator w = _windows.find(patch->model()->path());
+ assert( !view || view->patch() == patch);
+
+ PatchWindowMap::iterator w = _patch_windows.find(patch->path());
- if (w != _windows.end()) {
+ if (w != _patch_windows.end()) {
(*w).second->present();
} else if (preferred) {
- w = _windows.find(preferred->patch_controller()->model()->path());
+ w = _patch_windows.find(preferred->patch()->path());
assert((*w).second == preferred);
- preferred->set_patch(patch);
- _windows.erase(w);
- _windows[patch->model()->path()] = preferred;
+ preferred->set_patch(patch, view);
+ _patch_windows.erase(w);
+ _patch_windows[patch->path()] = preferred;
preferred->present();
} else {
- PatchWindow* win = create_new(patch);
+ PatchWindow* win = new_patch_window(patch, view);
win->present();
}
}
PatchWindow*
-WindowFactory::create_new(CountedPtr<PatchController> patch)
+WindowFactory::new_patch_window(CountedPtr<PatchModel> patch, CountedPtr<PatchView> view)
{
- // FIXME: can't just load "patch_win" and children because PatchWindow
- // loads things it really shouldn't.
- //Glib::RefPtr<Gnome::Glade::Xml> xml = GladeFactory::new_glade_reference("patch_win");
- Glib::RefPtr<Gnome::Glade::Xml> xml = GladeFactory::new_glade_reference();
+ assert( !view || view->patch() == patch);
+
+ Glib::RefPtr<Gnome::Glade::Xml> xml = GladeFactory::new_glade_reference("patch_win");
PatchWindow* win = NULL;
xml->get_widget_derived("patch_win", win);
assert(win);
- win->set_patch(patch);
- _windows[patch->model()->path()] = win;
+ win->set_patch(patch, view);
+ _patch_windows[patch->path()] = win;
win->signal_delete_event().connect(sigc::bind<0>(
- sigc::mem_fun(this, &WindowFactory::remove), win));
+ sigc::mem_fun(this, &WindowFactory::remove_patch_window), win));
return win;
}
bool
-WindowFactory::remove(PatchWindow* win, GdkEventAny* ignored)
+WindowFactory::remove_patch_window(PatchWindow* win, GdkEventAny* ignored)
{
- if (_windows.size() <= 1) {
+ if (_patch_windows.size() <= 1) {
Gtk::MessageDialog d(*win, "This is the last remaining open patch "
"window. Closing this window will exit Ingenuity (the engine will "
"remain running).\n\nAre you sure you want to quit?",
@@ -90,15 +148,145 @@ WindowFactory::remove(PatchWindow* win, GdkEventAny* ignored)
return false;
}
- std::map<Path, PatchWindow*>::iterator w
- = _windows.find(win->patch_controller()->model()->path());
+ PatchWindowMap::iterator w = _patch_windows.find(win->patch()->path());
+
+ assert((*w).second == win);
+ _patch_windows.erase(w);
+
+ delete win;
+
+ return true;
+}
+
+
+void
+WindowFactory::present_controls(CountedPtr<NodeModel> node)
+{
+ NodeControlWindow* win = control_window(node);
+
+ if (win) {
+ win->present();
+ } else {
+ win = new_control_window(node);
+ win->present();
+ }
+}
+
+
+NodeControlWindow*
+WindowFactory::new_control_window(CountedPtr<NodeModel> node)
+{
+ size_t poly = 1;
+ if (node->polyphonic())
+ poly = ((PatchModel*)node->parent().get())->poly();
+
+ NodeControlWindow* win = new NodeControlWindow(node, poly);
+
+ _control_windows[node->path()] = win;
+
+ win->signal_delete_event().connect(sigc::bind<0>(
+ sigc::mem_fun(this, &WindowFactory::remove_control_window), win));
+
+ return win;
+}
+
+
+bool
+WindowFactory::remove_control_window(NodeControlWindow* win, GdkEventAny* ignored)
+{
+ ControlWindowMap::iterator w = _control_windows.find(win->node()->path());
assert((*w).second == win);
- _windows.erase(w);
+ _control_windows.erase(w);
delete win;
return true;
}
+void
+WindowFactory::present_load_plugin(CountedPtr<PatchModel> patch, MetadataMap data)
+{
+ PatchWindowMap::iterator w = _patch_windows.find(patch->path());
+
+ if (w != _patch_windows.end())
+ _load_plugin_win->set_transient_for(*w->second);
+
+ _load_plugin_win->present(patch, data);
+}
+
+
+void
+WindowFactory::present_load_patch(CountedPtr<PatchModel> patch, MetadataMap data)
+{
+ PatchWindowMap::iterator w = _patch_windows.find(patch->path());
+
+ if (w != _patch_windows.end())
+ _load_patch_win->set_transient_for(*w->second);
+
+ _load_patch_win->set_merge(); // Import is the only choice
+
+ _load_patch_win->present(patch, data);
+}
+
+
+void
+WindowFactory::present_new_subpatch(CountedPtr<PatchModel> patch, MetadataMap data)
+{
+ PatchWindowMap::iterator w = _patch_windows.find(patch->path());
+
+ if (w != _patch_windows.end())
+ _new_subpatch_win->set_transient_for(*w->second);
+
+ _new_subpatch_win->present(patch, data);
+}
+
+
+void
+WindowFactory::present_load_subpatch(CountedPtr<PatchModel> patch, MetadataMap data)
+{
+ PatchWindowMap::iterator w = _patch_windows.find(patch->path());
+
+ if (w != _patch_windows.end())
+ _load_subpatch_win->set_transient_for(*w->second);
+
+ _load_subpatch_win->present(patch, data);
+}
+
+
+void
+WindowFactory::present_rename(CountedPtr<ObjectModel> object)
+{
+ PatchWindowMap::iterator w = _patch_windows.find(object->path());
+
+ if (w != _patch_windows.end())
+ _rename_win->set_transient_for(*w->second);
+
+ _rename_win->present(object);
+}
+
+
+void
+WindowFactory::present_properties(CountedPtr<NodeModel> node)
+{
+ CountedPtr<PatchModel> patch = PtrCast<PatchModel>(node);
+ if (patch) {
+
+ PatchWindowMap::iterator w = _patch_windows.find(patch->path());
+ if (w != _patch_windows.end())
+ _patch_properties_win->set_transient_for(*w->second);
+
+ _patch_properties_win->present(patch);
+
+ } else {
+
+ PatchWindowMap::iterator w = _patch_windows.find(node->parent()->path());
+ if (w != _patch_windows.end())
+ _node_properties_win->set_transient_for(*w->second);
+
+ _node_properties_win->present(node);
+ }
+}
+
+
} // namespace Ingenuity