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/debug.h"
27 #include "canvas/grid.h"
28 #include "canvas/scroll_group.h"
29 #include "canvas/text.h"
30 #include "canvas/widget.h"
32 #include "ardour_button.h"
33 #include "ui_config.h"
38 using namespace ARDOUR;
40 using namespace Gtkmm2ext;
43 #include "ardour/vst_types.h"
45 static const char* localedir = LOCALEDIR;
46 int vstfx_init (void*) { return 0; }
48 void vstfx_destroy_editor (VSTState*) {}
50 class LogReceiver : public Receiver
53 void receive (Transmitter::Channel chn, const char * str);
56 static LogReceiver log_receiver;
59 LogReceiver::receive (Transmitter::Channel chn, const char * str)
61 const char *prefix = "";
64 case Transmitter::Error:
67 case Transmitter::Info:
70 case Transmitter::Warning:
71 prefix = "[WARNING]: ";
73 case Transmitter::Fatal:
76 case Transmitter::Throw:
77 /* this isn't supposed to happen */
78 cerr << "Game Over\n";
82 /* note: iostreams are already thread-safe: no external
86 std::cout << prefix << str << std::endl;
88 if (chn == Transmitter::Fatal) {
93 /* ***************************************************************************/
94 /* ***************************************************************************/
95 /* ***************************************************************************/
97 class CANVAS_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
100 CANVAS_UI (int *argcp, char **argvp[], const char* localedir);
104 bool main_window_delete_event (GdkEventAny* ev) { finish (); return true; }
105 void finish () { quit (); }
106 Gtk::Window _main_window;
108 ArdourCanvas::Container* initialize_canvas (ArdourCanvas::Canvas& canvas);
110 void canvas_size_request (Gtk::Requisition* req);
111 void canvas_size_allocated (Gtk::Allocation& alloc);
113 ArdourCanvas::GtkCanvas* canvas;
114 ArdourCanvas::Container* group;
115 ArdourCanvas::Grid* grid;
117 ArdourButton test_button;
120 /* ***************************************************************************/
122 CANVAS_UI::CANVAS_UI (int *argcp, char **argvp[], const char* localedir)
123 : Gtkmm2ext::UI (PROGRAM_NAME, X_("gui"), argcp, argvp)
125 Gtkmm2ext::init (localedir);
126 UIConfiguration::instance().post_gui_init ();
128 Gtkmm2ext::WindowTitle title ("Canvas Test");
129 _main_window.set_title (title.get_string());
130 _main_window.set_flags (CAN_FOCUS);
131 _main_window.signal_delete_event().connect (sigc::mem_fun (*this, &CANVAS_UI::main_window_delete_event));
134 VBox* b = manage (new VBox);
135 Label* l = manage (new Label ("Hello there"));
137 canvas = new ArdourCanvas::GtkCanvas ();
138 group = initialize_canvas (*canvas);
140 canvas->signal_size_request().connect (sigc::mem_fun (*this, &CANVAS_UI::canvas_size_request));
141 canvas->signal_size_allocate().connect (sigc::mem_fun (*this, &CANVAS_UI::canvas_size_allocated));
142 test_button.signal_clicked.connect (sigc::mem_fun (*this, &CANVAS_UI::finish));
144 test_button.set_text ("Don't click me");
146 b->pack_start (*l, false, 0);
147 b->pack_start (*canvas, true, 0);
149 _main_window.add (*b);
150 _main_window.show_all ();
153 CANVAS_UI::~CANVAS_UI ()
158 CANVAS_UI::starting ()
160 Application* app = Application::instance ();
165 ArdourCanvas::Container*
166 CANVAS_UI::initialize_canvas (ArdourCanvas::Canvas& canvas)
168 using namespace ArdourCanvas;
169 canvas.set_background_color (rgba_to_color (0.0, 0.0, 0.4, 1.0));
171 ScrollGroup* scroll_group = new ScrollGroup (canvas.root(),
172 ScrollGroup::ScrollSensitivity (ScrollGroup::ScrollsVertically|ScrollGroup::ScrollsHorizontally));
174 grid = new ArdourCanvas::Grid (scroll_group);
176 grid->set_padding (40.0);
177 grid->set_margin (0.0);
179 grid->set_outline_width (3.0);
180 grid->set_outline_color (Color (0x3daec1ff));
181 grid->set_outline (false);
182 grid->set_row_spacing (60.0);
183 grid->set_col_spacing (3.0);
184 grid->set_homogenous (false);
186 ArdourCanvas::Text* text1 = new ArdourCanvas::Text (&canvas);
187 text1->set ("hello, world");
188 text1->set_color (Color (0xff0000ff));
190 ArdourCanvas::Text* text2 = new ArdourCanvas::Text (&canvas);
191 text2->set ("goodbye, cruel world");
192 text2->set_color (Color (0x00ff00ff));
194 ArdourCanvas::Text* text3 = new ArdourCanvas::Text (&canvas);
195 text3->set ("I am the third");
196 text3->set_color (Color (0xff00ffff));
198 ArdourCanvas::Text* text4 = new ArdourCanvas::Text (&canvas);
199 text4->set ("I am fourth");
200 text4->set_color (Color (0xffff00ff));
202 grid->place (text1, 0, 0, 2, 1);
203 grid->place (text2, 2, 0);
204 grid->place (text3, 0, 2, 1, 2);
205 grid->place (text4, 1, 3);
207 ArdourButton* button1 = new ArdourButton ("auto-return");
208 ArdourButton* button2 = new ArdourButton ("auto-play");
209 ArdourButton* button3 = new ArdourButton ("follow range");
210 ArdourButton* button4 = new ArdourButton ("auto-input");
212 ArdourCanvas::Widget* w1 = new ArdourCanvas::Widget (&canvas, *button1);
213 CANVAS_DEBUG_NAME (w1, "w1");
214 grid->place (w1, 3, 0, 2, 0);
215 ArdourCanvas::Widget* w2 = new ArdourCanvas::Widget (&canvas, *button2);
216 CANVAS_DEBUG_NAME (w2, "w2");
217 grid->place (w2, 5, 0, 2, 0);
218 ArdourCanvas::Widget* w3 = new ArdourCanvas::Widget (&canvas, *button3);
219 CANVAS_DEBUG_NAME (w3, "w3");
220 grid->place (w3, 3, 1);
221 ArdourCanvas::Widget* w4 = new ArdourCanvas::Widget (&canvas, *button4);
222 CANVAS_DEBUG_NAME (w4, "w4");
223 grid->place (w4, 4, 1);
225 //ArdourCanvas::Widget* w = new ArdourCanvas::Widget (scroll_group, test_button);
226 //CANVAS_DEBUG_NAME (w, "TheW");
228 return new ArdourCanvas::Container (scroll_group);
232 CANVAS_UI::canvas_size_request (Gtk::Requisition* req)
239 CANVAS_UI::canvas_size_allocated (Gtk::Allocation& alloc)
243 /* ***************************************************************************/
244 /* ***************************************************************************/
245 /* ***************************************************************************/
247 static CANVAS_UI *ui = 0;
249 int main (int argc, char **argv)
252 fixup_bundle_environment (argc, argv, localedir);
257 if (!ARDOUR::init (false, true, localedir)) {
258 cerr << "Ardour failed to initialize\n" << endl;
259 ::exit (EXIT_FAILURE);
262 if (!Glib::thread_supported()) {
266 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
268 log_receiver.listen_to (error);
269 log_receiver.listen_to (info);
270 log_receiver.listen_to (fatal);
271 log_receiver.listen_to (warning);
273 if (UIConfiguration::instance().pre_gui_init ()) {
274 error << _("Could not complete pre-GUI initialization") << endmsg;
278 // we could load a session here, if needed
279 // see ../session_utils/common.cc
281 ui = new CANVAS_UI (&argc, &argv, localedir);
282 ui->run (log_receiver);
284 info << "Farewell" << endmsg;
286 Gtkmm2ext::Application::instance()->cleanup();
291 pthread_cancel_all ();