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/actions.h"
18 #include "gtkmm2ext/application.h"
19 #include "gtkmm2ext/window_title.h"
20 #include "gtkmm2ext/gtk_ui.h"
21 #include "gtkmm2ext/utils.h"
23 #include "canvas/types.h"
24 #include "canvas/canvas.h"
25 #include "canvas/container.h"
26 #include "canvas/colors.h"
27 #include "canvas/debug.h"
28 #include "canvas/grid.h"
29 #include "canvas/scroll_group.h"
30 #include "canvas/text.h"
31 #include "canvas/widget.h"
33 #include "ardour_button.h"
34 #include "ui_config.h"
39 using namespace ARDOUR;
41 using namespace Gtkmm2ext;
44 #include "ardour/vst_types.h"
46 static const char* localedir = LOCALEDIR;
47 int vstfx_init (void*) { return 0; }
49 void vstfx_destroy_editor (VSTState*) {}
51 class LogReceiver : public Receiver
54 void receive (Transmitter::Channel chn, const char * str);
57 static LogReceiver log_receiver;
60 LogReceiver::receive (Transmitter::Channel chn, const char * str)
62 const char *prefix = "";
65 case Transmitter::Error:
68 case Transmitter::Info:
71 case Transmitter::Warning:
72 prefix = "[WARNING]: ";
74 case Transmitter::Fatal:
77 case Transmitter::Throw:
78 /* this isn't supposed to happen */
79 cerr << "Game Over\n";
83 /* note: iostreams are already thread-safe: no external
87 std::cout << prefix << str << std::endl;
89 if (chn == Transmitter::Fatal) {
94 /* ***************************************************************************/
95 /* ***************************************************************************/
96 /* ***************************************************************************/
99 make_transport_button (std::string const & action, Gtkmm2ext::ArdourIcon::Icon icon)
101 ArdourButton* button = new ArdourButton;
102 button->set_name ("transport button");
103 Glib::RefPtr<Gtk::Action> act;
104 act = ActionManager::get_action (action.c_str());
105 button->set_related_action (act);
106 button->set_icon (icon);
110 class CANVAS_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
113 CANVAS_UI (int *argcp, char **argvp[], const char* localedir);
117 bool main_window_delete_event (GdkEventAny* ev) { finish (); return true; }
118 void finish () { quit (); }
119 Gtk::Window _main_window;
121 void initialize_canvas (ArdourCanvas::Canvas& canvas);
123 void canvas_size_request (Gtk::Requisition* req);
124 void canvas_size_allocated (Gtk::Allocation& alloc);
126 ArdourCanvas::GtkCanvas* canvas;
127 ArdourCanvas::Container* group;
128 ArdourCanvas::Grid* grid;
130 ArdourButton test_button;
133 /* ***************************************************************************/
135 CANVAS_UI::CANVAS_UI (int *argcp, char **argvp[], const char* localedir)
136 : Gtkmm2ext::UI (PROGRAM_NAME, X_("gui"), argcp, argvp)
138 Gtkmm2ext::init (localedir);
139 UIConfiguration::instance().post_gui_init ();
141 Gtkmm2ext::WindowTitle title ("Canvas Toolbar Test");
142 _main_window.set_title (title.get_string());
143 _main_window.set_flags (CAN_FOCUS);
144 _main_window.signal_delete_event().connect (sigc::mem_fun (*this, &CANVAS_UI::main_window_delete_event));
146 canvas = new ArdourCanvas::GtkCanvas ();
148 initialize_canvas (*canvas);
150 canvas->signal_size_request().connect (sigc::mem_fun (*this, &CANVAS_UI::canvas_size_request));
151 canvas->signal_size_allocate().connect (sigc::mem_fun (*this, &CANVAS_UI::canvas_size_allocated));
153 _main_window.add (*canvas);
154 _main_window.show_all ();
157 CANVAS_UI::~CANVAS_UI ()
162 CANVAS_UI::starting ()
164 Application* app = Application::instance ();
170 CANVAS_UI::initialize_canvas (ArdourCanvas::Canvas& canvas)
172 using namespace ArdourCanvas;
173 canvas.set_background_color (rgba_to_color (0.0, 0.0, 0.4, 1.0));
175 ScrollGroup* scroll_group = new ScrollGroup (canvas.root(),
176 ScrollGroup::ScrollSensitivity (ScrollGroup::ScrollsVertically|ScrollGroup::ScrollsHorizontally));
178 grid = new ArdourCanvas::Grid (scroll_group);
180 grid->set_padding (3.0);
182 grid->set_row_spacing (3.0);
183 grid->set_col_spacing (3.0);
184 grid->set_homogenous (true);
186 ArdourCanvas::Widget* w1 = new ArdourCanvas::Widget (&canvas, *make_transport_button ("Transport/Roll", ArdourIcon::TransportPlay));
187 CANVAS_DEBUG_NAME (w1, "w1");
188 grid->place (w1, 0, 0);
189 ArdourCanvas::Widget* w2 = new ArdourCanvas::Widget (&canvas, *make_transport_button ("Transport/Stop", ArdourIcon::TransportStop));
190 CANVAS_DEBUG_NAME (w2, "w2");
191 grid->place (w2, 1, 0);
192 ArdourCanvas::Widget* w3 = new ArdourCanvas::Widget (&canvas, *make_transport_button ("Transport/Record", ArdourIcon::RecButton));
193 CANVAS_DEBUG_NAME (w3, "w3");
194 grid->place (w3, 2, 0);
195 ArdourCanvas::Widget* w4 = new ArdourCanvas::Widget (&canvas, *make_transport_button ("Transport/Loop", ArdourIcon::TransportLoop));
196 CANVAS_DEBUG_NAME (w4, "w4");
197 grid->place (w4, 3, 0);
201 CANVAS_UI::canvas_size_request (Gtk::Requisition* req)
203 ArdourCanvas::Rect bbox = canvas->root()->bounding_box();
204 req->width = bbox.width();
205 req->height = bbox.height();
209 CANVAS_UI::canvas_size_allocated (Gtk::Allocation& alloc)
213 /* ***************************************************************************/
214 /* ***************************************************************************/
215 /* ***************************************************************************/
217 static CANVAS_UI *ui = 0;
219 int main (int argc, char **argv)
222 fixup_bundle_environment (argc, argv, localedir);
227 if (!ARDOUR::init (false, true, localedir)) {
228 cerr << "Ardour failed to initialize\n" << endl;
229 ::exit (EXIT_FAILURE);
232 if (!Glib::thread_supported()) {
236 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
238 log_receiver.listen_to (error);
239 log_receiver.listen_to (info);
240 log_receiver.listen_to (fatal);
241 log_receiver.listen_to (warning);
243 if (UIConfiguration::instance().pre_gui_init ()) {
244 error << _("Could not complete pre-GUI initialization") << endmsg;
248 // we could load a session here, if needed
249 // see ../session_utils/common.cc
251 ui = new CANVAS_UI (&argc, &argv, localedir);
252 ui->run (log_receiver);
254 info << "Farewell" << endmsg;
256 Gtkmm2ext::Application::instance()->cleanup();
261 pthread_cancel_all ();