/[gluid]/callbacks.c
ViewVC logotype

Contents of /callbacks.c

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26