From 2481db7a7f77b7c2020f044aa685c6822c500dda Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 11 Dec 2016 15:45:42 +0100 Subject: [PATCH] Add a small tool to experiment with libcanvas --- gtk2_ardour/arcanvas | 5 + gtk2_ardour/canvas_test.cc | 239 +++++++++++++++++++++++++++++++++++++ gtk2_ardour/wscript | 30 +++++ wscript | 7 ++ 4 files changed, 281 insertions(+) create mode 100755 gtk2_ardour/arcanvas create mode 100644 gtk2_ardour/canvas_test.cc diff --git a/gtk2_ardour/arcanvas b/gtk2_ardour/arcanvas new file mode 100755 index 0000000000..8ad055bc60 --- /dev/null +++ b/gtk2_ardour/arcanvas @@ -0,0 +1,5 @@ +#!/bin/sh +TOP=`dirname "$0"`/.. +. $TOP/build/gtk2_ardour/ardev_common_waf.sh +export UBUNTU_MENUPROXY="" +exec $TOP/build/gtk2_ardour/canvas_test "$@" diff --git a/gtk2_ardour/canvas_test.cc b/gtk2_ardour/canvas_test.cc new file mode 100644 index 0000000000..9ccc242813 --- /dev/null +++ b/gtk2_ardour/canvas_test.cc @@ -0,0 +1,239 @@ +#include +#include +#include +#include + +#include "pbd/debug.h" +#include "pbd/error.h" +#include "pbd/failed_constructor.h" +#include "pbd/pthread_utils.h" +#include "pbd/receiver.h" +#include "pbd/transmitter.h" + +#include "ardour/audioengine.h" +#include "ardour/filename_extensions.h" +#include "ardour/types.h" + +#include "gtkmm2ext/application.h" +#include "gtkmm2ext/window_title.h" +#include "gtkmm2ext/gtk_ui.h" +#include "gtkmm2ext/utils.h" + +#include "canvas/types.h" +#include "canvas/canvas.h" +#include "canvas/container.h" +#include "canvas/colors.h" +#include "canvas/scroll_group.h" +#include "canvas/text.h" + +#include "ardour_button.h" +#include "ui_config.h" + +#include "pbd/i18n.h" + +using namespace std; +using namespace ARDOUR; +using namespace PBD; +using namespace Gtkmm2ext; +using namespace Gtk; + +#include "ardour/vst_types.h" + +static const char* localedir = LOCALEDIR; +int vstfx_init (void*) { return 0; } +void vstfx_exit () {} +void vstfx_destroy_editor (VSTState*) {} + +class LogReceiver : public Receiver +{ + protected: + void receive (Transmitter::Channel chn, const char * str); +}; + +static LogReceiver log_receiver; + +void +LogReceiver::receive (Transmitter::Channel chn, const char * str) +{ + const char *prefix = ""; + + switch (chn) { + case Transmitter::Error: + prefix = "[ERROR]: "; + break; + case Transmitter::Info: + prefix = "[INFO]: "; + break; + case Transmitter::Warning: + prefix = "[WARNING]: "; + break; + case Transmitter::Fatal: + prefix = "[FATAL]: "; + break; + case Transmitter::Throw: + /* this isn't supposed to happen */ + cerr << "Game Over\n"; + abort (); + } + + /* note: iostreams are already thread-safe: no external + lock required. + */ + + std::cout << prefix << str << std::endl; + + if (chn == Transmitter::Fatal) { + ::exit (9); + } +} + +/* ***************************************************************************/ +/* ***************************************************************************/ +/* ***************************************************************************/ + +class CANVAS_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr +{ +public: + CANVAS_UI (int *argcp, char **argvp[], const char* localedir); + ~CANVAS_UI(); +private: + int starting (); + bool main_window_delete_event (GdkEventAny* ev) { finish (); return true; } + void finish () { quit (); } + Gtk::Window _main_window; + + ArdourCanvas::Container* initialize_canvas (ArdourCanvas::Canvas& canvas); + + void canvas_size_request (Gtk::Requisition* req); + void canvas_size_allocated (Gtk::Allocation& alloc); + + ArdourCanvas::GtkCanvas* canvas; + ArdourCanvas::Container* group; + + ArdourButton test_button; +}; + +/* ***************************************************************************/ + +CANVAS_UI::CANVAS_UI (int *argcp, char **argvp[], const char* localedir) + : Gtkmm2ext::UI (PROGRAM_NAME, X_("gui"), argcp, argvp) +{ + Gtkmm2ext::init (localedir); + UIConfiguration::instance().post_gui_init (); + + Gtkmm2ext::WindowTitle title ("Canvas Test"); + _main_window.set_title (title.get_string()); + _main_window.set_flags (CAN_FOCUS); + _main_window.signal_delete_event().connect (sigc::mem_fun (*this, &CANVAS_UI::main_window_delete_event)); + + + VBox* b = manage (new VBox); + Label* l = manage (new Label ("Hello there")); + + canvas = new ArdourCanvas::GtkCanvas (); + group = initialize_canvas (*canvas); + + canvas->signal_size_request().connect (sigc::mem_fun (*this, &CANVAS_UI::canvas_size_request)); + canvas->signal_size_allocate().connect (sigc::mem_fun (*this, &CANVAS_UI::canvas_size_allocated)); + test_button.signal_clicked.connect (sigc::mem_fun (*this, &CANVAS_UI::finish)); + + test_button.set_text ("Don't click me"); + + b->pack_start (*l, false, 0); + b->pack_start (test_button, false, 0); + b->pack_start (*canvas, true, 0); + + _main_window.add (*b); + _main_window.show_all (); +} + +CANVAS_UI::~CANVAS_UI () +{ +} + +int +CANVAS_UI::starting () +{ + Application* app = Application::instance (); + app->ready (); + return 0; +} + +ArdourCanvas::Container* +CANVAS_UI::initialize_canvas (ArdourCanvas::Canvas& canvas) +{ + using namespace ArdourCanvas; + canvas.set_background_color (rgba_to_color (0.0, 0.0, 1.0, 1.0)); + + ScrollGroup* scroll_group = new ScrollGroup (canvas.root(), + ScrollGroup::ScrollSensitivity (ScrollGroup::ScrollsVertically|ScrollGroup::ScrollsHorizontally)); + + Text* text = new Text (scroll_group); + text->set ("Canvas Text"); + + return new ArdourCanvas::Container (scroll_group); +} + +void +CANVAS_UI::canvas_size_request (Gtk::Requisition* req) +{ + req->width = 100; + req->height = 100; +} + +void +CANVAS_UI::canvas_size_allocated (Gtk::Allocation& alloc) +{ +} + +/* ***************************************************************************/ +/* ***************************************************************************/ +/* ***************************************************************************/ + +static CANVAS_UI *ui = 0; + +int main (int argc, char **argv) +{ +#if 0 + fixup_bundle_environment (argc, argv, localedir); + load_custom_fonts(); + // TODO setlocale.. +#endif + + if (!ARDOUR::init (false, true, localedir)) { + cerr << "Ardour failed to initialize\n" << endl; + ::exit (EXIT_FAILURE); + } + + if (!Glib::thread_supported()) { + Glib::thread_init(); + } + + pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0); + + log_receiver.listen_to (error); + log_receiver.listen_to (info); + log_receiver.listen_to (fatal); + log_receiver.listen_to (warning); + + if (UIConfiguration::instance().pre_gui_init ()) { + error << _("Could not complete pre-GUI initialization") << endmsg; + exit (1); + } + + // we could load a session here, if needed + // see ../session_utils/common.cc + + ui = new CANVAS_UI (&argc, &argv, localedir); + ui->run (log_receiver); + + info << "Farewell" << endmsg; + + Gtkmm2ext::Application::instance()->cleanup(); + delete ui; + ui = 0; + + ARDOUR::cleanup (); + pthread_cancel_all (); + return 0; +} diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index eefe772b96..4b48bc9837 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -490,6 +490,36 @@ def build(bld): obj.defines += [ 'LXVST_SUPPORT' ] obj.use += [ 'X11' ] + # Tool to test libcanvas + if re.search ("linux", sys.platform) != None and bld.env['CANVASTESTUI']: + obj = bld (features = 'cxx c cxxprogram') + obj.install_path = None + obj.source = list(gtk2_ardour_sources) + obj.source = [ 'ardour_button.cc', 'ui_config.cc', 'tooltips.cc' ] + obj.target = 'canvas_test' + obj.includes = ['.', '../libs'] + obj.ldflags = ['-no-undefined'] + obj.use = [ + 'libpbd', + 'libardour', + 'libardour_cp', + 'libtimecode', + 'libmidipp', + 'libgtkmm2ext', + 'libcanvas', + 'libptformat', + ] + obj.defines = [ + 'NOMAIN', + 'PACKAGE="' + I18N_PACKAGE + '"', + 'DATA_DIR="' + os.path.normpath(bld.env['DATADIR']) + '"', + 'CONFIG_DIR="' + os.path.normpath(bld.env['SYSCONFDIR']) + '"', + 'LOCALEDIR="' + os.path.normpath(bld.env['LOCALEDIR']) + '"', + ] + obj.linkflags = '' + obj.uselib = 'UUID FLAC FONTCONFIG GLIBMM GTHREAD GTK OGG CURL DL GTKMM CANVAS FFTW3F LO TAGLIB XML ' + obj.source += [ 'canvas_test.cc', ] + if bld.is_defined('WINDOWS_VST_SUPPORT') and bld.env['build_target'] != 'mingw': # Windows VST support w/wine diff --git a/wscript b/wscript index 0c9b235c13..83866424d2 100644 --- a/wscript +++ b/wscript @@ -709,6 +709,8 @@ def options(opt): help='Use external/system versions of some bundled libraries') opt.add_option('--luadoc', action='store_true', default=False, dest='luadoc', help='Compile Tool to dump LuaBindings (needs C++11)') + opt.add_option('--canvasui', action='store_true', default=False, dest='canvasui', + help='Compile libcanvas test GUI') opt.add_option('--lv2', action='store_true', default=True, dest='lv2', help='Compile with support for LV2 (if Lilv+Suil is available)') opt.add_option('--no-lv2', action='store_false', dest='lv2', @@ -932,6 +934,10 @@ def configure(conf): print ('No Carbon support available for this build\n') + if Options.options.canvasui: + conf.env['CANVASTESTUI'] = True + conf.define ('CANVASTESTUI', 1) + if Options.options.luadoc: conf.env['LUABINDINGDOC'] = True conf.define ('LUABINDINGDOC', 1) @@ -1211,6 +1217,7 @@ const char* const ardour_config_info = "\\n\\ write_config_text('AudioUnits', conf.is_defined('AUDIOUNIT_SUPPORT')) write_config_text('Free/Demo copy', conf.is_defined('FREEBIE')) write_config_text('Build target', conf.env['build_target']) + write_config_text('Canvas Test UI', conf.is_defined('CANVASTESTUI')) write_config_text('CoreAudio', conf.is_defined('HAVE_COREAUDIO')) write_config_text('CoreAudio 10.5 compat', conf.is_defined('COREAUDIO105')) write_config_text('Debug RT allocations', conf.is_defined('DEBUG_RT_ALLOC'))