/[gluid]/callbacks.c
ViewVC logotype

Contents of /callbacks.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 24 - (show annotations)
Mon Sep 28 07:18:36 2009 UTC (11 years, 3 months ago) by ben
File MIME type: text/plain
File size: 9190 byte(s)
i18n (not tested)
1 /*
2 * callbacks.c Copyright © 2009 by Benoît Rouits <brouits@free.fr>
3 * Published under the terms of the GNU General Public License v2 (GPLv2).
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 * see the COPYING file included in the jackie package or
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt for the full licence
22 *
23 */
24
25 #include <gtk/gtk.h>
26 #include <fluidsynth.h>
27 #include <libintl.h>
28 #include <locale.h>
29 #include "utils.h"
30 #include "type.h"
31 #include "menu.h"
32 #include "about.h"
33 #include "version.h"
34 #define _(string) gettext (string)
35
36 /* handler for the volume button drag */
37 void volume_on_event (GtkWidget* instance, gdouble value, gpointer app_data) {
38 AppData* d = (AppData*) app_data;
39 fluid_synth_set_gain(d->synth,value*10.0);
40 instance = NULL;
41 app_data = NULL;
42 }
43
44 /* handler for left-button click */
45 void status_icon_on_left_click(GtkStatusIcon* instance, gpointer app_data) {
46 AppData* d = (AppData*) app_data;
47 GtkVolumeButton* volume;
48 GtkWidget* popup;
49 double curvol;
50
51 if (!d->synth) /* fluidsynth not started */
52 return;
53 volume = GTK_VOLUME_BUTTON(gtk_volume_button_new());
54 curvol = (fluid_synth_get_gain(d->synth)/10.0);
55 gtk_scale_button_set_value(GTK_SCALE_BUTTON(volume), curvol/10.0);
56 popup = gtk_scale_button_get_popup(GTK_SCALE_BUTTON(volume));
57 gtk_window_set_position(GTK_WINDOW(popup), GTK_WIN_POS_MOUSE);
58 g_signal_connect(G_OBJECT(volume), "value-changed", G_CALLBACK(volume_on_event), app_data);
59 g_signal_connect_swapped(popup, "leave-notify-event", G_CALLBACK(gtk_widget_destroy), popup);
60 gtk_widget_show_all(popup);
61 instance = app_data = NULL;
62 }
63
64 /* handler for right-button click */
65 void status_icon_on_right_click(GtkStatusIcon* instance, guint button, guint activate_time, gpointer app_data) {
66 AppData* d = (AppData*) app_data;
67
68 if (app_data)
69 menu_show (GTK_MENU(d->right_menu), button, activate_time);
70 instance = NULL;
71 }
72
73 int midi_ev_cb (void *data, fluid_midi_event_t *event) {
74 /* printf("event type: %d\n", fluid_midi_event_get_type(event)); */
75 /* FIXME print something on tooltip ? */
76 data = NULL;
77 event = NULL;
78 return 0;
79 }
80
81 /* handler for the "Play" menu item */
82 void menu_item_on_startstop(GtkMenuItem* instance, gpointer app_data) {
83 AppData* d = (AppData*) app_data;
84 if (!d->synth) { /* is stopped : start it */
85 d->settings = new_fluid_settings();
86 d->synth = new_fluid_synth(d->settings);
87 if (fluid_is_soundfont(d->sfpath)) {
88 fluid_synth_sfload(d->synth, d->sfpath, 1);
89 } else {
90 gtk_status_icon_set_tooltip(d->status_icon, "no sound font found");
91 goto stop;
92 }
93 fluid_settings_setstr(d->settings, "audio.driver", d->audio);
94 fluid_settings_setstr(d->settings, "midi.driver", d->midi);
95 d->adriver = new_fluid_audio_driver(d->settings, d->synth);
96 if (!d->adriver) /* backend already used */
97 goto stop;
98 d->router = new_fluid_midi_router(d->settings, fluid_synth_handle_midi_event, (void*)d->synth);
99 fluid_synth_set_midi_router(d->synth, d->router);
100 if (!d->router)
101 goto stop;
102 d->mdriver = new_fluid_midi_driver(d->settings, fluid_midi_router_handle_midi_event, (void*)d->router);
103 if (!d->mdriver) /* backend already used */
104 goto stop;
105 gtk_status_icon_set_tooltip(d->status_icon, "fluidsynth running");
106 gtk_menu_item_set_label(instance, _("Stop"));
107 } else { /* is started : stop it*/
108 stop:
109 if (d->mdriver)
110 delete_fluid_midi_driver(d->mdriver);
111 d->mdriver = NULL;
112 if (d->router)
113 delete_fluid_midi_router(d->router);
114 d->router = NULL;
115 if (d->adriver)
116 delete_fluid_audio_driver(d->adriver);
117 d->adriver = NULL;
118 if (d->synth)
119 delete_fluid_synth(d->synth);
120 d->synth = NULL;
121 if (d->settings)
122 delete_fluid_settings(d->settings);
123 d->settings = NULL;
124
125 gtk_status_icon_set_tooltip(d->status_icon, "fluidsynth stopped");
126 gtk_menu_item_set_label(instance, _("Start"));
127 }
128 }
129
130 /* handler for the "About" menu item (see version.h) */
131 void menu_item_on_about(GtkMenuItem* instance, gpointer unused) {
132 GtkAboutDialog* about;
133 const gchar* authors [] = {
134 PROG_AUTHOR0,
135 NULL
136 };
137
138 about = about_create (PROG_NAME, PROG_VERSION, PROG_COPYRIGHT,
139 PROG_COMMENT, PROG_LICENSE, PROG_WEBSITE,
140 authors);
141 about_show (about);
142 unused = NULL; /* avoid compiler warnings */
143 instance = NULL; /* _ */
144 return;
145 }
146
147 /* callback on Preferences window closed */
148 void pref_window_on_close (gpointer app_data) {
149 AppData* d = (AppData*) app_data;
150
151 g_free(d->sfpath);
152 d->sfpath = g_strdup (gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d->sfpath_chooser)));
153 g_free(d->audio);
154 d->audio = g_strdup (gtk_combo_box_get_active_text(d->audio_combo));
155 g_free(d->midi);
156 d->midi = g_strdup (gtk_combo_box_get_active_text(d->midi_combo));
157
158 /* write it to $HOME/.gluid */
159 write_config (d);
160 gtk_widget_hide (GTK_WIDGET(d->pref_window));
161 gtk_widget_destroy (GTK_WIDGET(d->pref_window));
162 gtk_widget_set_sensitive (GTK_WIDGET(d->pref_item), TRUE);
163 d->pref_window = NULL;
164 }
165
166 /* handler for the "Preference" menu item */
167 void menu_item_on_pref(GtkMenuItem* instance, gpointer app_data) {
168 AppData* d = (AppData*) app_data;
169 GtkVBox* vbox;
170 GtkHBox* hbox1;
171 GtkHBox* hbox2;
172 GtkHBox* hbox3;
173 GtkHBox* hbox4;
174 GtkLabel* label1;
175 GtkLabel* label2;
176 GtkLabel* label3;
177 GtkLabel* label4;
178 GtkButton* button1;
179
180 d->pref_window = GTK_WINDOW(gtk_window_new (GTK_WINDOW_TOPLEVEL));
181 gtk_window_set_title (GTK_WINDOW(d->pref_window), "Preferences");
182 gtk_window_set_default_size (GTK_WINDOW(d->pref_window), 300, 200);
183 gtk_window_set_resizable (GTK_WINDOW(d->pref_window), TRUE);
184
185 vbox = GTK_VBOX(gtk_vbox_new (TRUE, 0));
186 gtk_container_add (GTK_CONTAINER(d->pref_window), GTK_WIDGET(vbox));
187
188 hbox1 = GTK_HBOX(gtk_hbox_new (TRUE, 0));
189 gtk_box_pack_start (GTK_BOX(vbox), GTK_WIDGET(hbox1), TRUE, FALSE, 10);
190
191 hbox2 = GTK_HBOX(gtk_hbox_new (TRUE, 0));
192 gtk_box_pack_start (GTK_BOX(vbox), GTK_WIDGET(hbox2), TRUE, FALSE, 10);
193
194 hbox3 = GTK_HBOX(gtk_hbox_new (TRUE, 0));
195 gtk_box_pack_start (GTK_BOX(vbox), GTK_WIDGET(hbox3), TRUE, FALSE, 10);
196
197 hbox4 = GTK_HBOX(gtk_hbox_new (TRUE, 0));
198 gtk_box_pack_start (GTK_BOX(vbox), GTK_WIDGET(hbox4), TRUE, FALSE, 10);
199
200 label1= GTK_LABEL(gtk_label_new ("Soundfont Path:"));
201 gtk_box_pack_start (GTK_BOX(hbox1), GTK_WIDGET(label1), TRUE, FALSE, 10);
202 label2 = GTK_LABEL(gtk_label_new ("Audio Driver:"));
203 gtk_box_pack_start (GTK_BOX(hbox2), GTK_WIDGET(label2), TRUE, FALSE, 10);
204 label3 = GTK_LABEL(gtk_label_new ("Midi Driver:"));
205 gtk_box_pack_start (GTK_BOX(hbox3), GTK_WIDGET(label3), TRUE, FALSE, 10);
206
207 d->sfpath_chooser = GTK_FILE_CHOOSER_BUTTON(gtk_file_chooser_button_new("Choose SF2 file", GTK_FILE_CHOOSER_ACTION_OPEN));
208 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(d->sfpath_chooser), d->sfpath);
209 gtk_box_pack_start(GTK_BOX(hbox1), GTK_WIDGET(d->sfpath_chooser), TRUE, TRUE, 10);
210 d->audio_combo = GTK_COMBO_BOX(gtk_combo_box_new_text ());
211 gtk_combo_box_append_text (d->audio_combo, d->audio);
212 gtk_combo_box_append_text (d->audio_combo, "alsa");
213 gtk_combo_box_append_text (d->audio_combo, "jack");
214 gtk_combo_box_append_text (d->audio_combo, "oss");
215 gtk_combo_box_append_text (d->audio_combo, "file");
216 gtk_combo_box_set_active(d->audio_combo, 0);
217 gtk_box_pack_start(GTK_BOX(hbox2), GTK_WIDGET(d->audio_combo), TRUE, FALSE, 10);
218 d->midi_combo = GTK_COMBO_BOX(gtk_combo_box_new_text ());
219 gtk_combo_box_append_text (d->midi_combo, d->midi);
220 gtk_combo_box_append_text (d->midi_combo, "alsa_raw");
221 gtk_combo_box_append_text (d->midi_combo, "alsa_seq");
222 gtk_combo_box_append_text (d->midi_combo, "jack");
223 gtk_combo_box_append_text (d->midi_combo, "oss");
224 gtk_combo_box_set_active(d->midi_combo, 0);
225 gtk_box_pack_start(GTK_BOX(hbox3), GTK_WIDGET(d->midi_combo), TRUE, FALSE, 10);
226
227 label4 = GTK_LABEL(gtk_label_new (""));
228 gtk_box_pack_start (GTK_BOX(hbox4), GTK_WIDGET(label4), TRUE, FALSE, 10);
229
230 button1 = GTK_BUTTON(gtk_button_new_from_stock (GTK_STOCK_CLOSE));
231 gtk_box_pack_start (GTK_BOX(hbox4), GTK_WIDGET(button1), FALSE, FALSE, 10);
232
233 g_signal_connect_swapped (G_OBJECT(button1), "clicked", G_CALLBACK(pref_window_on_close), (gpointer)d);
234 g_signal_connect_swapped (G_OBJECT(d->pref_window), "delete-event", G_CALLBACK(pref_window_on_close), (gpointer)d);
235
236 gtk_widget_show_all (GTK_WIDGET(d->pref_window));
237 gtk_widget_set_sensitive (GTK_WIDGET(instance), FALSE);
238 }
239
240 /* handler for the "Quit" menu item */
241 void menu_item_on_quit(GtkMenuItem* instance, gpointer app_data) {
242 AppData* d = (AppData*) app_data;
243 quit (d);
244 instance = NULL; /* useless but does not warn at compile time */
245 }
246

  ViewVC Help
Powered by ViewVC 1.1.26