/*
This file is part of Ingen.
Copyright 2007-2015 David Robillard
Ingen is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free
Software Foundation, either version 3 of the License, or any later version.
Ingen is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU Affero General Public License for details.
You should have received a copy of the GNU Affero General Public License
along with Ingen. If not, see .
*/
#include
#include
#include
#include "ingen/Configuration.hpp"
#include "ingen/Interface.hpp"
#include "ingen/client/BlockModel.hpp"
#include "ingen/client/GraphModel.hpp"
#include "ingen/client/GroupModel.hpp"
#include "App.hpp"
#include "Style.hpp"
#include "GraphCanvas.hpp"
#include "GraphPortModule.hpp"
#include "GraphWindow.hpp"
#include "Port.hpp"
#include "PortMenu.hpp"
#include "RenameWindow.hpp"
#include "WidgetFactory.hpp"
#include "WindowFactory.hpp"
using namespace std;
namespace Ingen {
using namespace Client;
namespace GUI {
GraphPortModule::GraphPortModule(GraphCanvas& canvas,
SPtr gm,
SPtr pm)
: Ganv::Module(canvas, "", 0, 0, false) // FIXME: coords?
, _group(gm)
{
if (pm) {
set_stacked(pm->polyphonic());
if (pm->is_input() && !pm->is_numeric()) {
set_is_source(true);
}
}
if (gm) {
gm->signal_property().connect(
sigc::mem_fun(this, &GraphPortModule::property_changed));
} else if (pm) {
pm->signal_property().connect(
sigc::mem_fun(this, &GraphPortModule::property_changed));
}
signal_moved().connect(
sigc::mem_fun(this, &GraphPortModule::store_location));
}
GraphPortModule*
GraphPortModule::create(GraphCanvas& canvas,
SPtr gm,
SPtr pm)
{
GraphPortModule* ret = new GraphPortModule(canvas, gm, pm);
if (pm) {
Port* port = Port::create(canvas.app(), *ret, pm, true);
if (pm->is_numeric()) {
port->show_control();
}
}
for (const auto& p : ret->model()->properties()) {
ret->property_changed(p.first, p.second);
}
return ret;
}
SPtr
GraphPortModule::model()
{
if (_group) {
return _group;
} else if (Port* const port = get_port()) {
return port->model();
}
return SPtr();
}
Port*
GraphPortModule::get_port()
{
if (begin() == end()) {
return nullptr;
}
return dynamic_cast(*begin());
}
App&
GraphPortModule::app() const
{
return ((GraphCanvas*)canvas())->app();
}
bool
GraphPortModule::show_menu(GdkEventButton* ev)
{
if (Port* const port = get_port()) {
return port->show_menu(ev);
}
fprintf(stderr, "ERR\n");
return false;
}
void
GraphPortModule::store_location(double ax, double ay)
{
fprintf(stderr, "FIXME\n");
#if 0
const URIs& uris = app().uris();
const Atom x(app().forge().make(static_cast(ax)));
const Atom y(app().forge().make(static_cast(ay)));
if (x != _model->get_property(uris.ingen_canvasX) ||
y != _model->get_property(uris.ingen_canvasY))
{
app().interface()->put(
_model->uri(),
{{uris.ingen_canvasX, Property(x, Property::Graph::INTERNAL)},
{uris.ingen_canvasY, Property(y, Property::Graph::INTERNAL)}});
}
#endif
}
void
GraphPortModule::show_human_names(bool b)
{
const URIs& uris = app().uris();
const Atom& name = model()->get_property(uris.lv2_name);
if (b && name.type() == uris.forge.String) {
set_name(name.ptr());
} else {
set_name(model()->symbol().c_str());
}
}
void
GraphPortModule::set_name(const std::string& n)
{
if (_group) {
set_label(n.c_str());
} else if (Port* port = get_port()) {
port->set_label(n.c_str());
}
}
void
GraphPortModule::property_changed(const Raul::URI& key, const Atom& value)
{
const URIs& uris = app().uris();
if (value.type() == uris.forge.Float) {
if (key == uris.ingen_canvasX) {
move_to(value.get(), get_y());
} else if (key == uris.ingen_canvasY) {
move_to(get_x(), value.get());
}
} else if (value.type() == uris.forge.String) {
if (key == uris.lv2_name &&
app().world()->conf().option("human-names").get()) {
set_name(value.ptr());
} else if (key == uris.lv2_symbol &&
!app().world()->conf().option("human-names").get()) {
set_name(value.ptr());
}
} else if (value.type() == uris.forge.Bool) {
if (key == uris.ingen_polyphonic) {
set_stacked(value.get());
}
}
}
void
GraphPortModule::set_selected(gboolean b)
{
if (b != get_selected()) {
Module::set_selected(b);
}
}
} // namespace GUI
} // namespace Ingen