1 |
/* |
2 |
* Copyright (C) 2007 Andreas Persson |
3 |
* |
4 |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License as |
6 |
* published by the Free Software Foundation; either version 2, or (at |
7 |
* your option) any later version. |
8 |
* |
9 |
* This program is distributed in the hope that it will be useful, but |
10 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 |
* General Public License for more details. |
13 |
* |
14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with program; see the file COPYING. If not, write to the Free |
16 |
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
17 |
* 02110-1301 USA. |
18 |
*/ |
19 |
|
20 |
#include "gigedit.h" |
21 |
|
22 |
#include <gtkmm/main.h> |
23 |
#include "mainwindow.h" |
24 |
|
25 |
#include "global.h" |
26 |
|
27 |
// the app has to work from a DLL as well, so we hard code argv |
28 |
int argc = 1; |
29 |
const char* argv_c[] = { "gigedit" }; |
30 |
char** argv = const_cast<char**>(argv_c); |
31 |
//FIXME: Gtk only allows to instantiate one Gtk::Main object per process, so this might crash other Gtk applications, i.e. launched as plugins by LinuxSampler |
32 |
Gtk::Main kit(argc, argv); |
33 |
|
34 |
static void __init_app() { |
35 |
static bool process_initialized = false; |
36 |
if (!process_initialized) { |
37 |
std::cout << "Initializing 3rd party services needed by gigedit.\n" |
38 |
<< std::flush; |
39 |
setlocale(LC_ALL, ""); |
40 |
|
41 |
#if HAVE_GETTEXT |
42 |
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); |
43 |
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); |
44 |
textdomain(GETTEXT_PACKAGE); |
45 |
#endif // HAVE_GETTEXT |
46 |
|
47 |
// make sure thread_init() is called once and ONLY once per process |
48 |
if (!Glib::thread_supported()) Glib::thread_init(); |
49 |
|
50 |
process_initialized = true; |
51 |
} |
52 |
} |
53 |
|
54 |
static void __connect_signals(GigEdit* gigedit, MainWindow* mainwindow) { |
55 |
// the signals of the "GigEdit" class are actually just proxies, that |
56 |
// is they simply forward the signals of the internal classes to the |
57 |
// outer world |
58 |
mainwindow->signal_file_structure_to_be_changed().connect( |
59 |
gigedit->signal_file_structure_to_be_changed().make_slot() |
60 |
); |
61 |
mainwindow->signal_file_structure_changed().connect( |
62 |
gigedit->signal_file_structure_changed().make_slot() |
63 |
); |
64 |
mainwindow->signal_samples_to_be_removed().connect( |
65 |
gigedit->signal_samples_to_be_removed().make_slot() |
66 |
); |
67 |
mainwindow->signal_samples_removed().connect( |
68 |
gigedit->signal_samples_removed().make_slot() |
69 |
); |
70 |
mainwindow->signal_region_to_be_changed().connect( |
71 |
gigedit->signal_region_to_be_changed().make_slot() |
72 |
); |
73 |
mainwindow->signal_region_changed().connect( |
74 |
gigedit->signal_region_changed().make_slot() |
75 |
); |
76 |
mainwindow->signal_dimreg_to_be_changed().connect( |
77 |
gigedit->signal_dimreg_to_be_changed().make_slot() |
78 |
); |
79 |
mainwindow->signal_dimreg_changed().connect( |
80 |
gigedit->signal_dimreg_changed().make_slot() |
81 |
); |
82 |
mainwindow->signal_sample_ref_changed().connect( |
83 |
gigedit->signal_sample_ref_changed().make_slot() |
84 |
); |
85 |
} |
86 |
|
87 |
int GigEdit::run() { |
88 |
__init_app(); |
89 |
MainWindow window; |
90 |
__connect_signals(this, &window); |
91 |
kit.run(window); |
92 |
return 0; |
93 |
} |
94 |
|
95 |
int GigEdit::run(const char* pFileName) { |
96 |
__init_app(); |
97 |
MainWindow window; |
98 |
__connect_signals(this, &window); |
99 |
if (pFileName) window.load_file(pFileName); |
100 |
kit.run(window); |
101 |
return 0; |
102 |
} |
103 |
|
104 |
int GigEdit::run(gig::Instrument* pInstrument) { |
105 |
__init_app(); |
106 |
MainWindow window; |
107 |
__connect_signals(this, &window); |
108 |
if (pInstrument) window.load_instrument(pInstrument); |
109 |
kit.run(window); |
110 |
return 0; |
111 |
} |
112 |
|
113 |
sigc::signal<void, gig::File*>& GigEdit::signal_file_structure_to_be_changed() { |
114 |
return file_structure_to_be_changed_signal; |
115 |
} |
116 |
|
117 |
sigc::signal<void, gig::File*>& GigEdit::signal_file_structure_changed() { |
118 |
return file_structure_changed_signal; |
119 |
} |
120 |
|
121 |
sigc::signal<void, std::list<gig::Sample*> >& GigEdit::signal_samples_to_be_removed() { |
122 |
return samples_to_be_removed_signal; |
123 |
} |
124 |
|
125 |
sigc::signal<void>& GigEdit::signal_samples_removed() { |
126 |
return samples_removed_signal; |
127 |
} |
128 |
|
129 |
sigc::signal<void, gig::Region*>& GigEdit::signal_region_to_be_changed() { |
130 |
return region_to_be_changed_signal; |
131 |
} |
132 |
|
133 |
sigc::signal<void, gig::Region*>& GigEdit::signal_region_changed() { |
134 |
return region_changed_signal; |
135 |
} |
136 |
|
137 |
sigc::signal<void, gig::DimensionRegion*>& GigEdit::signal_dimreg_to_be_changed() { |
138 |
return dimreg_to_be_changed_signal; |
139 |
} |
140 |
|
141 |
sigc::signal<void, gig::DimensionRegion*>& GigEdit::signal_dimreg_changed() { |
142 |
return dimreg_changed_signal; |
143 |
} |
144 |
|
145 |
sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& GigEdit::signal_sample_ref_changed() { |
146 |
return sample_ref_changed_signal; |
147 |
} |