/[gluid]/callbacks.c
ViewVC logotype

Contents of /callbacks.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 15 - (show annotations)
Sat Sep 26 18:33:09 2009 UTC (10 years, 8 months ago) by ben
File MIME type: text/plain
File size: 8963 byte(s)
300x200 pref window
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 "utils.h"
28 #include "type.h"
29 #include "menu.h"
30 #include "about.h"
31 #include "version.h"
32
33 /* handler for the volume button drag */
34 void volume_on_event (GtkWidget* instance, gdouble value, gpointer app_data) {
35 AppData* d = (AppData*) app_data;
36 fluid_synth_set_gain(d->synth,value*10.0);
37 instance = NULL;
38 app_data = NULL;
39 }
40
41 /* handler for left-button click */
42 void status_icon_on_left_click(GtkStatusIcon* instance, gpointer app_data) {
43 AppData* d = (AppData*) app_data;
44 GtkVolumeButton* volume;
45 GtkWidget* popup;
46 double curvol;
47
48 if (!d->synth) /* fluidsynth not started */
49 return;
50 volume = GTK_VOLUME_BUTTON(gtk_volume_button_new());
51 curvol = (fluid_synth_get_gain(d->synth)/10.0);
52 gtk_scale_button_set_value(GTK_SCALE_BUTTON(volume), curvol/10.0);
53 popup = gtk_scale_button_get_popup(GTK_SCALE_BUTTON(volume));
54 gtk_window_set_position(GTK_WINDOW(popup), GTK_WIN_POS_MOUSE);
55 g_signal_connect(G_OBJECT(volume), "value-changed", G_CALLBACK(volume_on_event), app_data);
56 g_signal_connect_swapped(popup, "leave-notify-event", G_CALLBACK(gtk_widget_destroy), popup);
57 gtk_widget_show_all(popup);
58 instance = app_data = NULL;
59 }
60
61 /* handler for right-button click */
62 void status_icon_on_right_click(GtkStatusIcon* instance, guint button, guint activate_time, gpointer app_data) {
63 AppData* d = (AppData*) app_data;
64
65 if (app_data)
66 menu_show (GTK_MENU(d->right_menu), button, activate_time);
67 instance = NULL;
68 }
69
70 int midi_ev_cb (void *data, fluid_midi_event_t *event) {
71 /* printf("event type: %d\n", fluid_midi_event_get_type(event)); */
72 /* FIXME print something on tooltip ? */
73 data = NULL;
74 event = NULL;
75 return 0;
76 }
77
78 /* handler for the "Play" menu item */
79 void menu_item_on_startstop(GtkMenuItem* instance, gpointer app_data) {
80 AppData* d = (AppData*) app_data;
81 if (!d->synth) { /* is stopped : start it */
82 d->settings = new_fluid_settings();
83 d->synth = new_fluid_synth(d->settings);
84 if (fluid_is_soundfont(d->sfpath)) {
85 fluid_synth_sfload(d->synth, d->sfpath, 1);
86 } else {
87 gtk_status_icon_set_tooltip(d->status_icon, "no sound font found");
88 goto stop;
89 }
90 fluid_settings_setstr(d->settings, "audio.driver", d->audio);
91 fluid_settings_setstr(d->settings, "midi.driver", d->midi);
92 d->adriver = new_fluid_audio_driver(d->settings, d->synth);
93 if (!d->adriver) /* backend already used */
94 goto stop;
95 d->router = new_fluid_midi_router(d->settings, fluid_synth_handle_midi_event, (void*)d->synth);
96 fluid_synth_set_midi_router(d->synth, d->router);
97 if (!d->router)
98 goto stop;
99 d->mdriver = new_fluid_midi_driver(d->settings, fluid_midi_router_handle_midi_event, (void*)d->router);
100 if (!d->mdriver) /* backend already used */
101 goto stop;
102 gtk_status_icon_set_tooltip(d->status_icon, "fluidsynth running");
103 gtk_menu_item_set_label(instance, "Stop");
104 } else { /* is started : stop it*/
105 stop:
106 if (d->mdriver)
107 delete_fluid_midi_driver(d->mdriver);
108 d->mdriver = NULL;
109 if (d->router)
110 delete_fluid_midi_router(d->router);
111 d->router = NULL;
112 if (d->adriver)
113 delete_fluid_audio_driver(d->adriver);
114 d->adriver = NULL;
115 if (d->synth)
116 delete_fluid_synth(d->synth);
117 d->synth = NULL;
118 if (d->settings)
119 delete_fluid_settings(d->settings);
120 d->settings = NULL;
121
122 gtk_status_icon_set_tooltip(d->status_icon, "fluidsynth stopped");
123 gtk_menu_item_set_label(instance, "Start");
124 }
125 }
126
127 /* handler for the "About" menu item (see version.h) */
128 void menu_item_on_about(GtkMenuItem* instance, gpointer unused) {
129 GtkAboutDialog* about;
130 const gchar* authors [] = {
131 PROG_AUTHOR0,
132 NULL
133 };
134
135 about = about_create (PROG_NAME, PROG_VERSION, PROG_COPYRIGHT,
136 PROG_COMMENT, PROG_LICENSE, PROG_WEBSITE,
137 authors);
138 about_show (about);
139 unused = NULL; /* avoid compiler warnings */
140 instance = NULL; /* _ */
141 return;
142 }
143
144 /* callback on Preferences window closed */
145 void pref_window_on_close (gpointer app_data) {
146 AppData* d = (AppData*) app_data;
147
148 g_free(d->sfpath);
149 d->sfpath = g_strdup (gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d->sfpath_chooser)));
150 g_free(d->audio);
151 d->audio = g_strdup (gtk_combo_box_get_active_text(d->audio_combo));
152 g_free(d->midi);
153 d->midi = g_strdup (gtk_combo_box_get_active_text(d->midi_combo));
154
155 /* write it to $HOME/.gluid */
156 write_config (d);
157 gtk_widget_hide (GTK_WIDGET(d->pref_window));
158 gtk_widget_destroy (GTK_WIDGET(d->pref_window));
159 d->pref_window = NULL;
160 }
161
162 /* handler for the "Preference" menu item */
163 void menu_item_on_pref(GtkMenuItem* instance, gpointer app_data) {
164 AppData* d = (AppData*) app_data;
165 GtkVBox* vbox;
166 GtkHBox* hbox1;
167 GtkHBox* hbox2;
168 GtkHBox* hbox3;
169 GtkHBox* hbox4;
170 GtkLabel* label1;
171 GtkLabel* label2;
172 GtkLabel* label3;
173 GtkLabel* label4;
174 GtkButton* button1;
175
176 d->pref_window = GTK_WINDOW(gtk_window_new (GTK_WINDOW_TOPLEVEL));
177 gtk_window_set_title (GTK_WINDOW(d->pref_window), "Preferences");
178 gtk_window_set_default_size (GTK_WINDOW(d->pref_window), 300, 200);
179 gtk_window_set_resizable (GTK_WINDOW(d->pref_window), TRUE);
180
181 vbox = GTK_VBOX(gtk_vbox_new (TRUE, 0));
182 gtk_container_add (GTK_CONTAINER(d->pref_window), GTK_WIDGET(vbox));
183
184 hbox1 = GTK_HBOX(gtk_hbox_new (TRUE, 0));
185 gtk_box_pack_start (GTK_BOX(vbox), GTK_WIDGET(hbox1), TRUE, FALSE, 0);
186
187 hbox2 = GTK_HBOX(gtk_hbox_new (TRUE, 0));
188 gtk_box_pack_start (GTK_BOX(vbox), GTK_WIDGET(hbox2), TRUE, FALSE, 0);
189
190 hbox3 = GTK_HBOX(gtk_hbox_new (TRUE, 0));
191 gtk_box_pack_start (GTK_BOX(vbox), GTK_WIDGET(hbox3), TRUE, FALSE, 0);
192
193 hbox4 = GTK_HBOX(gtk_hbox_new (TRUE, 0));
194 gtk_box_pack_start (GTK_BOX(vbox), GTK_WIDGET(hbox4), TRUE, FALSE, 0);
195
196 label1= GTK_LABEL(gtk_label_new ("Soundfont Path:"));
197 gtk_box_pack_start (GTK_BOX(hbox1), GTK_WIDGET(label1), TRUE, FALSE, 0);
198 label2 = GTK_LABEL(gtk_label_new ("Audio Driver:"));
199 gtk_box_pack_start (GTK_BOX(hbox2), GTK_WIDGET(label2), TRUE, FALSE, 0);
200 label3 = GTK_LABEL(gtk_label_new ("Midi Driver:"));
201 gtk_box_pack_start (GTK_BOX(hbox3), GTK_WIDGET(label3), TRUE, FALSE, 0);
202
203 d->sfpath_chooser = GTK_FILE_CHOOSER_BUTTON(gtk_file_chooser_button_new("Choose SF2 file", GTK_FILE_CHOOSER_ACTION_OPEN));
204 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(d->sfpath_chooser), d->sfpath);
205 gtk_box_pack_start(GTK_BOX(hbox1), GTK_WIDGET(d->sfpath_chooser), TRUE, FALSE, 0);
206 d->audio_combo = GTK_COMBO_BOX(gtk_combo_box_new_text ());
207 gtk_combo_box_append_text (d->audio_combo, d->audio);
208 gtk_combo_box_append_text (d->audio_combo, "alsa");
209 gtk_combo_box_append_text (d->audio_combo, "jack");
210 gtk_combo_box_append_text (d->audio_combo, "oss");
211 gtk_combo_box_append_text (d->audio_combo, "file");
212 gtk_combo_box_set_active(d->audio_combo, 0);
213 gtk_box_pack_start(GTK_BOX(hbox2), GTK_WIDGET(d->audio_combo), TRUE, FALSE, 0);
214 d->midi_combo = GTK_COMBO_BOX(gtk_combo_box_new_text ());
215 gtk_combo_box_append_text (d->midi_combo, d->midi);
216 gtk_combo_box_append_text (d->midi_combo, "alsa_seq");
217 gtk_combo_box_append_text (d->midi_combo, "jack");
218 gtk_combo_box_append_text (d->midi_combo, "oss");
219 gtk_combo_box_set_active(d->midi_combo, 0);
220 gtk_box_pack_start(GTK_BOX(hbox3), GTK_WIDGET(d->midi_combo), TRUE, FALSE, 0);
221
222 label4 = GTK_LABEL(gtk_label_new (""));
223 gtk_box_pack_start (GTK_BOX(hbox4), GTK_WIDGET(label4), TRUE, FALSE, 0);
224
225 button1 = GTK_BUTTON(gtk_button_new_from_stock (GTK_STOCK_CLOSE));
226 gtk_box_pack_start (GTK_BOX(hbox4), GTK_WIDGET(button1), FALSE, FALSE, 0);
227
228 g_signal_connect_swapped (G_OBJECT(button1), "clicked", G_CALLBACK(pref_window_on_close), (gpointer)d);
229 g_signal_connect_swapped (G_OBJECT(d->pref_window), "delete-event", G_CALLBACK(pref_window_on_close), (gpointer)d);
230
231 gtk_widget_show_all (GTK_WIDGET(d->pref_window));
232 instance = NULL; /* avoid warnings */
233 }
234
235 /* handler for the "Quit" menu item */
236 void menu_item_on_quit(GtkMenuItem* instance, gpointer app_data) {
237 AppData* d = (AppData*) app_data;
238 quit (d);
239 instance = NULL; /* useless but does not warn at compile time */
240 }
241

  ViewVC Help
Powered by ViewVC 1.1.26