-
Notifications
You must be signed in to change notification settings - Fork 25
/
gwaon-menu.c
210 lines (168 loc) · 6.26 KB
/
gwaon-menu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* gWaoN -- gtk+ Spectra Analyzer : menu
* Copyright (C) 2007-2013 Kengo Ichiki <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h> /* fprintf() */
#include <gtk/gtk.h>
#include <string.h> // memset()
// libsndfile
#include <sndfile.h>
#include "gwaon-about.h" /* create_about() */
#include "gwaon-wav.h" /* create_wav() */
static void
on_quit (GtkWidget *widget, gpointer data)
{
gtk_main_quit ();
}
static void
on_preference (void)
{
}
/* Get the selected filename and print it to the console */
static void
on_file_open_wav_sel_ok (GtkWidget *widget, GtkFileSelection *fs)
{
extern SNDFILE *sf;
extern SF_INFO sfinfo;
gchar *filename =
(gchar *) gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
g_print ("%s\n", filename);
// close sf first, if sf is open
if (sf != NULL)
{
sf_close (sf);
}
// open the file
memset (&sfinfo, 0, sizeof (sfinfo));
sf = sf_open (filename, SFM_READ, &sfinfo);
if (sf == NULL)
{
g_print ("fail to open %s\n", filename);
return;
}
g_print ("channels = %d\n", sfinfo.channels);
g_print ("samplerate = %d\n", sfinfo.samplerate);
g_print ("frames = %d\n", (int)sfinfo.frames);
create_wav ();
gtk_widget_destroy (GTK_WIDGET (fs));
}
static void
on_file_open_wav (GtkWidget *widget, gpointer data)
{
/* Create a new file selection widget */
GtkWidget *filew = gtk_file_selection_new ("File selection");
gtk_signal_connect (GTK_OBJECT (filew), "destroy",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT (filew));
/* Connect the ok_button to file_ok_sel function */
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
"clicked",
(GtkSignalFunc) on_file_open_wav_sel_ok, filew );
/* Connect the cancel_button to destroy the widget */
gtk_signal_connect_object (GTK_OBJECT
(GTK_FILE_SELECTION (filew)->cancel_button),
"clicked", (GtkSignalFunc) gtk_widget_destroy,
GTK_OBJECT (filew));
/* Lets set the filename, as if this were a save dialog, and we are giving
a default filename */
gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew),
"test.wav");
gtk_widget_show(filew);
}
void
create_menu (void)
{
// create a new window
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
/*gtk_widget_set_usize( GTK_WIDGET (window), 200, 100);*/
gtk_widget_set_uposition (window, 200, 100);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT (window));
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC (on_quit), NULL);
/*gtk_signal_connect_after (GTK_OBJECT (window), "key_press_event",
GTK_SIGNAL_FUNC (on_key_press_event), NULL);
gtk_signal_connect (GTK_OBJECT (window), "expose_event",
GTK_SIGNAL_FUNC (on_expose_event), NULL);*/
gtk_widget_realize (window);
gtk_window_set_title(GTK_WINDOW (window), "gWaoN");
gtk_container_border_width (GTK_CONTAINER (window), 0);
GtkTooltips *tooltips = gtk_tooltips_new ();
GtkAccelGroup *accel_group = gtk_accel_group_new ();
GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_widget_show (vbox);
/* create menu bar */
GtkWidget *menubar = gtk_menu_bar_new ();
gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, TRUE, 0);
gtk_widget_show (menubar);
/* create File menu */
GtkWidget *menuitem = gtk_menu_item_new_with_label ("File");
gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem);
gtk_widget_show (menuitem);
GtkWidget *menu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
/* File -> Open WAV */
menuitem = gtk_menu_item_new_with_label ("Open WAV");
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (on_file_open_wav), NULL);
gtk_widget_add_accelerator (menuitem, "activate", accel_group,
'O', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_tooltips_set_tip (tooltips, menuitem,
"Open an existing project", NULL);
gtk_widget_show (menuitem);
/* --separator-- */
menuitem = gtk_menu_item_new ();
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_widget_show (menuitem);
/* File -> Preferences */
menuitem = gtk_menu_item_new_with_label ("Preferences");
gtk_signal_connect_object (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (on_preference),
NULL);
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_tooltips_set_tip (tooltips, menuitem, "Edit project preferences",
NULL);
gtk_widget_show (menuitem);
/* --separator-- */
menuitem = gtk_menu_item_new ();
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_widget_show (menuitem);
/* File -> Exit */
menuitem = gtk_menu_item_new_with_label ("Exit");
gtk_signal_connect_object (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (on_quit),
NULL);
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_tooltips_set_tip (tooltips, menuitem, "Exit gWaoN",
NULL);
gtk_widget_show (menuitem);
/* Create Help menu */
menuitem = gtk_menu_item_new_with_label ("Help");
gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem);
gtk_widget_show (menuitem);
menu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
/* Help -> About */
menuitem = gtk_menu_item_new_with_label ("About...");
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (create_about), NULL);
gtk_widget_show (menuitem);
gtk_widget_show (window);
}