2 #include <gtkmm/main.h>
4 #include <gtkmm/window.h>
8 #include "pbd/failed_constructor.h"
9 #include "pbd/pthread_utils.h"
10 #include "pbd/receiver.h"
11 #include "pbd/transmitter.h"
13 #include "ardour/audioengine.h"
14 #include "ardour/filename_extensions.h"
15 #include "ardour/types.h"
17 #include "gtkmm2ext/application.h"
18 #include "gtkmm2ext/window_title.h"
19 #include "gtkmm2ext/gtk_ui.h"
20 #include "gtkmm2ext/utils.h"
22 #include "canvas/types.h"
23 #include "canvas/canvas.h"
24 #include "canvas/container.h"
25 #include "canvas/colors.h"
26 #include "canvas/scroll_group.h"
27 #include "canvas/text.h"
28 #include "canvas/widget.h"
30 #include "ardour_button.h"
31 #include "ui_config.h"
36 using namespace ARDOUR;
38 using namespace Gtkmm2ext;
41 #include "ardour/vst_types.h"
43 static const char* localedir = LOCALEDIR;
44 int vstfx_init (void*) { return 0; }
46 void vstfx_destroy_editor (VSTState*) {}
48 class LogReceiver : public Receiver
51 void receive (Transmitter::Channel chn, const char * str);
54 static LogReceiver log_receiver;
57 LogReceiver::receive (Transmitter::Channel chn, const char * str)
59 const char *prefix = "";
62 case Transmitter::Error:
65 case Transmitter::Info:
68 case Transmitter::Warning:
69 prefix = "[WARNING]: ";
71 case Transmitter::Fatal:
74 case Transmitter::Throw:
75 /* this isn't supposed to happen */
76 cerr << "Game Over\n";
80 /* note: iostreams are already thread-safe: no external
84 std::cout << prefix << str << std::endl;
86 if (chn == Transmitter::Fatal) {
91 /* ***************************************************************************/
92 /* ***************************************************************************/
93 /* ***************************************************************************/
95 class CANVAS_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
98 CANVAS_UI (int *argcp, char **argvp[], const char* localedir);
102 bool main_window_delete_event (GdkEventAny* ev) { finish (); return true; }
103 void finish () { quit (); }
104 Gtk::Window _main_window;
106 ArdourCanvas::Container* initialize_canvas (ArdourCanvas::Canvas& canvas);
108 void canvas_size_request (Gtk::Requisition* req);
109 void canvas_size_allocated (Gtk::Allocation& alloc);
111 ArdourCanvas::GtkCanvas* canvas;
112 ArdourCanvas::Container* group;
114 ArdourButton test_button;
117 /* ***************************************************************************/
119 CANVAS_UI::CANVAS_UI (int *argcp, char **argvp[], const char* localedir)
120 : Gtkmm2ext::UI (PROGRAM_NAME, X_("gui"), argcp, argvp)
122 Gtkmm2ext::init (localedir);
123 UIConfiguration::instance().post_gui_init ();
125 Gtkmm2ext::WindowTitle title ("Canvas Test");
126 _main_window.set_title (title.get_string());
127 _main_window.set_flags (CAN_FOCUS);
128 _main_window.signal_delete_event().connect (sigc::mem_fun (*this, &CANVAS_UI::main_window_delete_event));
131 VBox* b = manage (new VBox);
132 Label* l = manage (new Label ("Hello there"));
134 canvas = new ArdourCanvas::GtkCanvas ();
135 group = initialize_canvas (*canvas);
137 canvas->signal_size_request().connect (sigc::mem_fun (*this, &CANVAS_UI::canvas_size_request));
138 canvas->signal_size_allocate().connect (sigc::mem_fun (*this, &CANVAS_UI::canvas_size_allocated));
139 test_button.signal_clicked.connect (sigc::mem_fun (*this, &CANVAS_UI::finish));
141 test_button.set_text ("Don't click me");
143 b->pack_start (*l, false, 0);
144 b->pack_start (*canvas, true, 0);
146 _main_window.add (*b);
147 _main_window.show_all ();
150 CANVAS_UI::~CANVAS_UI ()
155 CANVAS_UI::starting ()
157 Application* app = Application::instance ();
162 ArdourCanvas::Container*
163 CANVAS_UI::initialize_canvas (ArdourCanvas::Canvas& canvas)
165 using namespace ArdourCanvas;
166 canvas.set_background_color (rgba_to_color (0.0, 0.0, 1.0, 1.0));
168 ScrollGroup* scroll_group = new ScrollGroup (canvas.root(),
169 ScrollGroup::ScrollSensitivity (ScrollGroup::ScrollsVertically|ScrollGroup::ScrollsHorizontally));
171 ArdourCanvas::Widget* w = new ArdourCanvas::Widget (scroll_group, test_button);
173 return new ArdourCanvas::Container (scroll_group);
177 CANVAS_UI::canvas_size_request (Gtk::Requisition* req)
184 CANVAS_UI::canvas_size_allocated (Gtk::Allocation& alloc)
188 /* ***************************************************************************/
189 /* ***************************************************************************/
190 /* ***************************************************************************/
192 static CANVAS_UI *ui = 0;
194 int main (int argc, char **argv)
197 fixup_bundle_environment (argc, argv, localedir);
202 if (!ARDOUR::init (false, true, localedir)) {
203 cerr << "Ardour failed to initialize\n" << endl;
204 ::exit (EXIT_FAILURE);
207 if (!Glib::thread_supported()) {
211 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
213 log_receiver.listen_to (error);
214 log_receiver.listen_to (info);
215 log_receiver.listen_to (fatal);
216 log_receiver.listen_to (warning);
218 if (UIConfiguration::instance().pre_gui_init ()) {
219 error << _("Could not complete pre-GUI initialization") << endmsg;
223 // we could load a session here, if needed
224 // see ../session_utils/common.cc
226 ui = new CANVAS_UI (&argc, &argv, localedir);
227 ui->run (log_receiver);
229 info << "Farewell" << endmsg;
231 Gtkmm2ext::Application::instance()->cleanup();
236 pthread_cancel_all ();