extract track and instrument names from SMF while loading
[ardour.git] / gtk2_ardour / canvas_test.cc
1 #include <glibmm.h>
2 #include <gtkmm/main.h>
3 #include <gtkmm/box.h>
4 #include <gtkmm/window.h>
5
6 #include "pbd/debug.h"
7 #include "pbd/error.h"
8 #include "pbd/failed_constructor.h"
9 #include "pbd/pthread_utils.h"
10 #include "pbd/receiver.h"
11 #include "pbd/transmitter.h"
12
13 #include "ardour/audioengine.h"
14 #include "ardour/filename_extensions.h"
15 #include "ardour/types.h"
16
17 #include "gtkmm2ext/application.h"
18 #include "gtkmm2ext/window_title.h"
19 #include "gtkmm2ext/gtk_ui.h"
20 #include "gtkmm2ext/utils.h"
21
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
29 #include "ardour_button.h"
30 #include "ui_config.h"
31
32 #include "pbd/i18n.h"
33
34 using namespace std;
35 using namespace ARDOUR;
36 using namespace PBD;
37 using namespace Gtkmm2ext;
38 using namespace Gtk;
39
40 #include "ardour/vst_types.h"
41
42 static const char* localedir = LOCALEDIR;
43 int vstfx_init (void*) { return 0; }
44 void vstfx_exit () {}
45 void vstfx_destroy_editor (VSTState*) {}
46
47 class LogReceiver : public Receiver
48 {
49   protected:
50     void receive (Transmitter::Channel chn, const char * str);
51 };
52
53 static LogReceiver log_receiver;
54
55 void
56 LogReceiver::receive (Transmitter::Channel chn, const char * str)
57 {
58         const char *prefix = "";
59
60         switch (chn) {
61         case Transmitter::Error:
62                 prefix = "[ERROR]: ";
63                 break;
64         case Transmitter::Info:
65                 prefix = "[INFO]: ";
66                 break;
67         case Transmitter::Warning:
68                 prefix = "[WARNING]: ";
69                 break;
70         case Transmitter::Fatal:
71                 prefix = "[FATAL]: ";
72                 break;
73         case Transmitter::Throw:
74                 /* this isn't supposed to happen */
75                 cerr << "Game Over\n";
76                 abort ();
77         }
78
79         /* note: iostreams are already thread-safe: no external
80            lock required.
81         */
82
83         std::cout << prefix << str << std::endl;
84
85         if (chn == Transmitter::Fatal) {
86                 ::exit (9);
87         }
88 }
89
90 /* ***************************************************************************/
91 /* ***************************************************************************/
92 /* ***************************************************************************/
93
94 class CANVAS_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
95 {
96 public:
97         CANVAS_UI (int *argcp, char **argvp[], const char* localedir);
98         ~CANVAS_UI();
99 private:
100         int starting ();
101         bool main_window_delete_event (GdkEventAny* ev) { finish (); return true; }
102         void finish () { quit (); }
103         Gtk::Window _main_window;
104
105         ArdourCanvas::Container* initialize_canvas (ArdourCanvas::Canvas& canvas);
106
107         void canvas_size_request (Gtk::Requisition* req);
108         void canvas_size_allocated (Gtk::Allocation& alloc);
109
110         ArdourCanvas::GtkCanvas* canvas;
111         ArdourCanvas::Container* group;
112
113         ArdourButton test_button;
114 };
115
116 /* ***************************************************************************/
117
118 CANVAS_UI::CANVAS_UI (int *argcp, char **argvp[], const char* localedir)
119         : Gtkmm2ext::UI (PROGRAM_NAME, X_("gui"), argcp, argvp)
120 {
121         Gtkmm2ext::init (localedir);
122         UIConfiguration::instance().post_gui_init ();
123
124         Gtkmm2ext::WindowTitle title ("Canvas Test");
125         _main_window.set_title (title.get_string());
126         _main_window.set_flags (CAN_FOCUS);
127         _main_window.signal_delete_event().connect (sigc::mem_fun (*this, &CANVAS_UI::main_window_delete_event));
128
129
130         VBox* b = manage (new VBox);
131         Label* l = manage (new Label ("Hello there"));
132
133         canvas = new ArdourCanvas::GtkCanvas ();
134         group = initialize_canvas (*canvas);
135
136         canvas->signal_size_request().connect (sigc::mem_fun (*this, &CANVAS_UI::canvas_size_request));
137         canvas->signal_size_allocate().connect (sigc::mem_fun (*this, &CANVAS_UI::canvas_size_allocated));
138         test_button.signal_clicked.connect (sigc::mem_fun (*this, &CANVAS_UI::finish));
139
140         test_button.set_text ("Don't click me");
141
142         b->pack_start (*l, false, 0);
143         b->pack_start (test_button, false, 0);
144         b->pack_start (*canvas, true, 0);
145
146         _main_window.add (*b);
147         _main_window.show_all ();
148 }
149
150 CANVAS_UI::~CANVAS_UI ()
151 {
152 }
153
154 int
155 CANVAS_UI::starting ()
156 {
157         Application* app = Application::instance ();
158         app->ready ();
159         return 0;
160 }
161
162 ArdourCanvas::Container*
163 CANVAS_UI::initialize_canvas (ArdourCanvas::Canvas& canvas)
164 {
165         using namespace ArdourCanvas;
166         canvas.set_background_color (rgba_to_color (0.0, 0.0, 1.0, 1.0));
167
168         ScrollGroup* scroll_group = new ScrollGroup (canvas.root(),
169                         ScrollGroup::ScrollSensitivity (ScrollGroup::ScrollsVertically|ScrollGroup::ScrollsHorizontally));
170
171         Text* text = new Text (scroll_group);
172         text->set ("Canvas Text");
173
174         return new ArdourCanvas::Container (scroll_group);
175 }
176
177 void
178 CANVAS_UI::canvas_size_request (Gtk::Requisition* req)
179 {
180         req->width = 100;
181         req->height = 100;
182 }
183
184 void
185 CANVAS_UI::canvas_size_allocated (Gtk::Allocation& alloc)
186 {
187 }
188
189 /* ***************************************************************************/
190 /* ***************************************************************************/
191 /* ***************************************************************************/
192
193 static CANVAS_UI  *ui = 0;
194
195 int main (int argc, char **argv)
196 {
197 #if 0
198         fixup_bundle_environment (argc, argv, localedir);
199         load_custom_fonts();
200         // TODO setlocale..
201 #endif
202
203         if (!ARDOUR::init (false, true, localedir)) {
204                 cerr << "Ardour failed to initialize\n" << endl;
205                 ::exit (EXIT_FAILURE);
206         }
207
208         if (!Glib::thread_supported()) {
209                 Glib::thread_init();
210         }
211
212         pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
213
214         log_receiver.listen_to (error);
215         log_receiver.listen_to (info);
216         log_receiver.listen_to (fatal);
217         log_receiver.listen_to (warning);
218
219         if (UIConfiguration::instance().pre_gui_init ()) {
220                 error << _("Could not complete pre-GUI initialization") << endmsg;
221                 exit (1);
222         }
223
224         // we could load a session here, if needed
225         // see ../session_utils/common.cc
226
227         ui = new CANVAS_UI (&argc, &argv, localedir);
228         ui->run (log_receiver);
229
230         info << "Farewell" << endmsg;
231
232         Gtkmm2ext::Application::instance()->cleanup();
233         delete ui;
234         ui = 0;
235
236         ARDOUR::cleanup ();
237         pthread_cancel_all ();
238         return 0;
239 }