-
Notifications
You must be signed in to change notification settings - Fork 7
/
gwc.c
3753 lines (3259 loc) · 128 KB
/
gwc.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************
* Gnome Wave Cleaner Version 0.21
* Copyright (C) 2001,2002,2003,2004,2005,2006 Jeffrey J. Welty
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*******************************************************************************/
/* gwc.c */
#include <errno.h>
#include <stdlib.h>
#include <stdarg.h>
#include <libgen.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include "gwc.h"
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <glib.h>
#include "gtkledbar.h"
#include "encoding.h"
#include "soundfile.h"
#include "audio_edit.h"
#include <sndfile.h>
#include "icons/amplify_dark.xpm"
#include "icons/amplify.xpm"
#include "icons/declick_dark.xpm"
#include "icons/declick_m_dark.xpm"
#include "icons/declick_m.xpm"
#include "icons/declick_w_dark.xpm"
#include "icons/declick_w.xpm"
#include "icons/declick.xpm"
#include "icons/decrackle_dark.xpm"
#include "icons/decrackle.xpm"
#include "icons/estimate_dark.xpm"
#include "icons/estimate.xpm"
#include "icons/filter_dark.xpm"
#include "icons/filter.xpm"
#include "icons/gtk-wave-cleaner.xpm"
#include "icons/noise_sample_dark.xpm"
#include "icons/noise_sample.xpm"
#include "icons/pinknoise_dark.xpm"
#include "icons/pinknoise.xpm"
#include "icons/remove_noise_dark.xpm"
#include "icons/remove_noise.xpm"
#include "icons/select_all_dark.xpm"
#include "icons/select_all.xpm"
#include "icons/silence_dark.xpm"
#include "icons/silence.xpm"
#include "icons/spectral_dark.xpm"
#include "icons/spectral.xpm"
#include "icons/start_dark.xpm"
#include "icons/start.xpm"
#include "icons/stop_dark.xpm"
#include "icons/stop.xpm"
#include "icons/view_all_dark.xpm"
#include "icons/view_all.xpm"
#include "icons/zoom_in_dark.xpm"
#include "icons/zoom_in.xpm"
#include "icons/zoom_out_dark.xpm"
#include "icons/zoom_out.xpm"
#include "icons/zoom_sel_dark.xpm"
#include "icons/zoom_sel.xpm"
#ifndef TRUNCATE_OLD
#endif
#ifdef MAC_OS_X
// Note that we only tested if we are building on OSX, and are just assuming we are building with the GDK QUARTZ backend.
// We should really check that, as we could be building with the X11 backend.
#include <gtkmacintegration/gtkosxapplication.h>
//#import <Cocoa/Cocoa.h>
#endif
char pathname[PATH_MAX+1] = "./";
GtkWidget *dial[2];
GtkWidget *audio_canvas_w;
GtkWidget *audio_drawing_area;
GdkPixmap *audio_pixmap = NULL;
GdkPixmap *highlight_pixmap = NULL;
GdkPixmap *cursor_pixmap = NULL;
GtkObject *scroll_pos;
GtkWidget *hscrollbar;
GtkWidget *detect_only_widget;
GtkWidget *leave_click_marks_widget;
GtkWidget *main_window;
GtkWidget *l_file_time;
GtkWidget *l_file_samples;
GtkWidget *l_file_channels;
GtkWidget *l_file_rate;
GtkWidget *l_first_time;
GtkWidget *l_selected_time;
GtkWidget *l_last_time;
GtkWidget *l_samples;
struct sound_prefs prefs;
struct denoise_prefs denoise_prefs;
struct encoding_prefs encoding_prefs;
struct view audio_view;
struct click_data click_data;
int audio_playback = FALSE;
int audio_is_looping = FALSE;
//int cursor_playback = FALSE;
int batch_mode = 0 ;
long cursor_samples_per_playback_block;
gint playback_timer = -1 ;
gint cursor_timer;
gint spectral_view_flag = FALSE;
gint repair_clicks = 1;
double view_scale = 1.0;
double declick_sensitivity = 0.75;
double weak_declick_sensitivity = 1.00;
double strong_declick_sensitivity = 0.75;
double weak_fft_declick_sensitivity = 3.0 ;
double strong_fft_declick_sensitivity = 5.0 ;
int declick_detector_type = FFT_DETECT ;
double stop_key_highlight_interval = 0.5;
double song_key_highlight_interval = 15;
double song_mark_silence = 2.0;
int sonogram_log = 0;
gint declick_iterate_flag = 0;
double decrackle_level = 0.2;
gint decrackle_window = 2000;
gint decrackle_average = 3;
gint encoding_type = GWC_OGG;
extern double spectral_amp;
#ifdef HAVE_ALSA
char audio_device[256]="default";
#else
char audio_device[256]="/dev/dsp";
#endif
gint window_x;
gint window_y;
gint window_width = 800;
gint window_height = 580;
gboolean window_maximised;
gint doing_progressbar_update = FALSE;
DENOISE_DATA denoise_data = { 0, 0, 0, 0, FALSE };
gint debug = 0;
gchar save_selection_filename[PATH_MAX+1];
gchar wave_filename[PATH_MAX+1];
gchar last_filename[PATH_MAX+1];
gchar *file_extension;
gchar *tmpdir;
gchar *CLIPBOARD_FILE;
long markers[MAX_MARKERS];
long n_markers = 0;
long num_song_markers = 0;
long song_markers[MAX_MARKERS];
/* The file selection widget and the string to store the chosen filename */
GtkWidget *file_selector;
gchar *selected_filename;
gint file_is_open = FALSE;
gint file_processing = FALSE;
int stop_playback_force = 1 ;
void d_print(char *fmt, ...)
{
if (debug) {
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
}
}
static int audio_debug = 1 ;
void usage(char *prog)
{
fprintf(stderr, "Usage:\n\
%s\n\
%s [file]\n\
%s <file> <batch[s] declick sensitivity start_position stop_position>\n\
%s <file> <batch[s] declick-hpf sensitivity start_position stop_position>\n\
%s <file> <batch[s] amplify amount start_position stop_position>\n\
%s <file> <batch[s] denoise sample_start sample_end denoise_start denoise_end>\n\
%s <file> <batch[s] normalize>\n\
%s <file> <batch[s] dsp start_position stop_position>\n\
%s <file> <batch[s] reverb start_position stop_position>\n\
%s <file> <batch[s] truncate keep_start keep_end>\n\
Positions are in hh:mm:ss for batch or in samples for batchs. Stop_position can \
also be end to denote the stop_position being the end of file.\n",
prog, prog, prog, prog, prog, prog, prog, prog, prog, prog);
exit(EXIT_FAILURE);
}
void audio_debug_print(char *fmt, ...)
{
if (audio_debug) {
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
}
}
char *sample_to_time_text(long i, int rate, char *prefix, char *buf)
{
int m, s, ms;
m = i / (rate * 60);
i -= m * rate * 60;
s = i / rate;
i -= s * rate;
ms = 1000 * i / rate;
sprintf(buf, "%s%d:%02d:%03d", prefix, m, s, ms);
return buf;
}
void shellsort_long(long a[], int n)
{
int gap, i, j;
long tmp;
for (gap = n / 2; gap > 0; gap /= 2) {
for (i = gap; i < n; i++) {
for (j = i - gap; j >= 0 && a[j] > a[j + gap]; j -= gap) {
tmp = a[j];
a[j] = a[j + gap];
a[j + gap] = tmp;
}
}
}
}
#ifndef TRUNCATE_OLD
static int is_region_selected(void)
{
if (!audio_view.selection_region) {
info("Please select a region of audio data.");
return 0;
}
return 1;
}
#endif /* !TRUNCATE_OLD */
void append_cdrdao(struct view *v)
{
// without this check it will append to cdrdao.toc even if no file is open
if (file_is_open) {
FILE *fp = fopen("cdrdao.toc", "a");
long first, last ;
if (fp == NULL) {
fp = fopen("cdrdao.toc", "w");
}
if (fp == NULL) {
warning(g_strconcat("Cannot write to ", g_get_current_dir(), "/cdrdao.toc: ", strerror(errno), NULL)); //this check prevents a segfault if we can't write to the file
}
else {
get_region_of_interest(&first, &last, v) ;
fprintf(fp, "TRACK AUDIO\n");
fprintf(fp, "FILE \"%s\" %ld %ld\n", wave_filename, first, last - first + 1);
fclose(fp);
set_status_text(g_strconcat("Selection appended to ", g_get_current_dir(), "/cdrdao.toc", NULL)); //we should really review the code looking for other actions that should set the status like this
}
}
}
void display_times(void)
{
char buf[50];
long first, last;
get_region_of_interest(&first, &last, &audio_view);
#ifndef OLD
sprintf(buf, "Audio Channels: %d", prefs.stereo+1);
gtk_label_set_text(GTK_LABEL(l_file_channels), buf);
sprintf(buf, "Samplerate: %d Hz", prefs.rate);
gtk_label_set_text(GTK_LABEL(l_file_rate), buf);
gtk_label_set_text(GTK_LABEL(l_file_time),
sample_to_time_text(prefs.n_samples, prefs.rate,
"Track Length ", buf));
sprintf(buf, "Track samples: %ld", audio_view.n_samples);
gtk_label_set_text(GTK_LABEL(l_file_samples), buf);
gtk_label_set_text(GTK_LABEL(l_first_time),
sample_to_time_text(first, prefs.rate, "First ",
buf));
gtk_label_set_text(GTK_LABEL(l_last_time),
sample_to_time_text(last, prefs.rate, "Last ",
buf));
gtk_label_set_text(GTK_LABEL(l_selected_time),
sample_to_time_text(last-first-1, prefs.rate, "Selected ",
buf));
sprintf(buf, "Samples: %ld", last - first + 1);
gtk_label_set_text(GTK_LABEL(l_samples), buf);
#else
gtk_label_set_text(GTK_LABEL(l_file_time),
sample_to_time_text(prefs.n_samples, prefs.rate, "",
buf));
gtk_label_set_text(GTK_LABEL(l_first_time),
sample_to_time_text(first, prefs.rate, "", buf));
gtk_label_set_text(GTK_LABEL(l_last_time),
sample_to_time_text(last, prefs.rate, "", buf));
sprintf(buf, " %ld", last - first + 1);
gtk_label_set_text(GTK_LABEL(l_samples), buf);
#endif
}
void set_scroll_bar(long n, long first, long last)
{
GtkAdjustment *a = (GtkAdjustment *) scroll_pos;
double dn = n;
double df = first;
double dl = last;
double ps = dl - df;
a->lower = 0;
a->upper = dn;
a->value = df;
a->page_size = ps;
a->step_increment = ps / 8.0;
a->page_increment = ps * 0.95;
/* scroll_pos = gtk_adjustment_new(1.0, 0.0, 100.0, 10.0, 20.0, 20.0) ; */
/* a->lower = 0 ; */
/* a->upper = 100.0 ; */
/* a->value = 10.0 ; */
/* a->step_increment = 10.0 ; */
/* a->page_increment = 20.0 ; */
/* a->page_size = 20.0 ; */
gtk_adjustment_changed(a);
}
void scroll_bar_changed(GtkWidget * widget, gpointer data)
{
GtkAdjustment *a = (GtkAdjustment *) scroll_pos;
audio_view.first_sample = MAX(0, MIN(prefs.n_samples - 1, a->value));
audio_view.last_sample =
MAX(0, MIN(prefs.n_samples - 1, a->value + a->page_size));
main_redraw(FALSE, TRUE);
/* pause 1/3 second to allow the user to release the mouse button */
usleep(333);
}
void get_region_of_interest(long *first, long *last, struct view *v)
{
*first = v->selected_first_sample;
*last = v->selected_last_sample;
if (v->selection_region == FALSE) {
*first = v->first_sample;
*last = v->last_sample;
}
}
GKeyFile* read_config(void)
{
gchar *config_file;
GKeyFile *key_file = NULL;
GError *error = NULL;
config_file = g_build_filename (g_get_user_config_dir (), APPNAME, SETTINGS_FILE, NULL);
//fprintf(stderr, "%s \n", config_file);
key_file = g_key_file_new ();
if (! g_key_file_load_from_file (key_file, config_file, G_KEY_FILE_KEEP_COMMENTS, &error)) {
if (error->code != G_IO_ERROR_NOT_FOUND)
// this is expected when running for the first time
// therefore don't use g_warning, which will error if G_DEBUG environment variable is set to "fatal-warnings"
g_message ("Could not load options file: %s\n", error->message);
g_clear_error (&error);
}
g_free (config_file);
return(key_file);
}
void write_config(GKeyFile *key_file)
{
gchar *file_data;
gchar *config_file;
file_data = g_key_file_to_data (key_file, NULL, NULL);
if (g_mkdir_with_parents (g_build_filename (g_get_user_config_dir (), APPNAME, NULL), 0755) != -1) {
config_file = g_build_filename (g_get_user_config_dir (), APPNAME, SETTINGS_FILE, NULL);
g_file_set_contents (config_file, file_data, -1, NULL);
g_free (config_file);
}
else
g_printerr ("Could not write settings file: %s\n", strerror (errno));
g_free (file_data);
g_key_file_free (key_file);
}
void load_preferences(void)
{
GKeyFile *key_file = read_config();
// We should probably have a separate test for each preference...
if (g_key_file_has_group(key_file, "config") == TRUE) {
strcpy(pathname, g_key_file_get_string(key_file, "config", "pathname", NULL));
strcpy(last_filename, g_key_file_get_string(key_file, "config", "last_filename", NULL));
audio_view.first_sample = g_key_file_get_integer(key_file, "config", "first_sample_viewed", NULL);
audio_view.last_sample = g_key_file_get_integer(key_file, "config", "last_sample_viewed", NULL);
// What's going on here with num_song_markers?
num_song_markers = 0;
weak_declick_sensitivity = g_key_file_get_double(key_file, "config", "weak_declick_sensitivity", NULL);
strong_declick_sensitivity = g_key_file_get_double(key_file, "config", "strong_declick_sensitivity", NULL);
declick_iterate_flag = g_key_file_get_integer(key_file, "config", "declick_iterate", NULL);
weak_fft_declick_sensitivity = g_key_file_get_double(key_file, "config", "weak_fft_declick_sensitivity", NULL);
strong_fft_declick_sensitivity = g_key_file_get_double(key_file, "config", "strong_fft_declick_sensitivity", NULL);
declick_detector_type = g_key_file_get_integer(key_file, "config", "declick_detector_type", NULL);
decrackle_level = g_key_file_get_double(key_file, "config", "decrackle_level", NULL);
decrackle_window = g_key_file_get_integer(key_file, "config", "decrackle_window", NULL);
decrackle_average = g_key_file_get_integer(key_file, "config", "decrackle_average", NULL);
stop_key_highlight_interval = g_key_file_get_double(key_file, "config", "stop_key_highlight_interval", NULL);
song_key_highlight_interval = g_key_file_get_double(key_file, "config", "song_key_highlight_interval", NULL);
song_mark_silence = g_key_file_get_double(key_file, "config", "song_mark_silence", NULL);
sonogram_log = g_key_file_get_double(key_file, "config", "sonogram_log", NULL);
/* audio_view.truncate_tail = g_key_file_get_integer(key_file, "config", "truncate_tail", NULL) ; */
/* audio_view.truncate_head = g_key_file_get_integer(key_file, "config", "truncate_head", NULL) ; */
strcpy(audio_device, g_key_file_get_string(key_file, "config", "audio_device", NULL));
}
if (g_key_file_has_group(key_file, "window") == TRUE) {
window_width = g_key_file_get_integer(key_file, "window", "width", NULL);
window_height = g_key_file_get_integer(key_file, "window", "height", NULL);
window_x = g_key_file_get_integer(key_file, "window", "x", NULL);
window_y = g_key_file_get_integer(key_file, "window", "y", NULL);
window_maximised = g_key_file_get_boolean(key_file, "window", "maximised", NULL);
}
g_key_file_free (key_file);
}
void save_preferences(void)
{
GKeyFile *key_file = read_config();
g_key_file_set_string(key_file, "config", "pathname", pathname);
g_key_file_set_string(key_file, "config", "last_filename", last_filename);
g_key_file_set_integer(key_file, "config", "first_sample_viewed", audio_view.first_sample);
g_key_file_set_integer(key_file, "config", "last_sample_viewed", audio_view.last_sample);
g_key_file_set_double(key_file, "config", "weak_declick_sensitivity", weak_declick_sensitivity);
g_key_file_set_double(key_file, "config", "strong_declick_sensitivity", strong_declick_sensitivity);
g_key_file_set_integer(key_file, "config", "declick_iterate", declick_iterate_flag);
g_key_file_set_double(key_file, "config", "weak_fft_declick_sensitivity", weak_fft_declick_sensitivity);
g_key_file_set_double(key_file, "config", "strong_fft_declick_sensitivity", strong_fft_declick_sensitivity);
g_key_file_set_integer(key_file, "config", "declick_detector_type", declick_detector_type);
g_key_file_set_double(key_file, "config", "decrackle_level", decrackle_level);
g_key_file_set_integer(key_file, "config", "decrackle_window", decrackle_window);
g_key_file_set_integer(key_file, "config", "decrackle_average", decrackle_average);
g_key_file_set_double(key_file, "config", "stop_key_highlight_interval", stop_key_highlight_interval);
g_key_file_set_double(key_file, "config", "song_key_highlight_interval", song_key_highlight_interval);
g_key_file_set_double(key_file, "config", "song_mark_silence", song_mark_silence);
g_key_file_set_integer(key_file, "config", "sonogram_log", sonogram_log);
g_key_file_set_string(key_file, "config", "audio_device", audio_device);
g_key_file_set_integer(key_file, "window", "width", window_width);
g_key_file_set_integer(key_file, "window", "height", window_height);
g_key_file_set_integer(key_file, "window", "x", window_x);
g_key_file_set_integer(key_file, "window", "y", window_y);
g_key_file_set_boolean(key_file, "window", "maximised", window_maximised);
/* g_key_file_set_integer(key_file, "config", "truncate_head", audio_view.truncate_head) ; */
/* g_key_file_set_integer(key_file, "config", "truncate_tail", audio_view.truncate_tail) ; */
write_config(key_file);
}
/* void main_set_preferences(GtkWidget * widget, gpointer data) */
/* { */
/* preferences_dialog(prefs); */
/* } */
void display_message(char *msg, char *title)
{
GtkWidget *dlg, *txt;
dlg = gtk_dialog_new_with_buttons(title,
GTK_WINDOW(main_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_OK,
GTK_RESPONSE_NONE,
NULL);
txt = gtk_label_new(msg);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), txt, TRUE, TRUE, 0) ;
/* Alister: disable since we have the file_selector closing even if opening fails
// Also for the matching code in other functions
// Alister: doing this (and for the other dialogs?) means that if the user raises
// another window above gwc, then clicks on the dialog, the main_window
// isn't raised, only the two dialogs.
// But that is better than if we don't do this, in which case the user can raise the
// file_selector dialog above the display_message dialog.
if (GTK_WIDGET_VISIBLE(file_selector)) {
gtk_window_set_transient_for((GtkWindow*) dlg, (GtkWindow*) file_selector);
}*/
gtk_widget_show_all(dlg) ;
gtk_dialog_run(GTK_DIALOG(dlg)) ;
gtk_widget_destroy(txt) ;
gtk_widget_destroy(dlg) ;
main_redraw(FALSE, TRUE);
}
void warning(char *msg)
{
display_message(msg, "WARNING");
}
void info(char *msg)
{
display_message(msg, "");
}
int yesnocancel(char *msg)
{
GtkWidget *dlg, *text;
gint dres;
dlg =
gtk_dialog_new_with_buttons("Question",
GTK_WINDOW(main_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
GTK_STOCK_NO,
GTK_RESPONSE_NO,
GTK_STOCK_YES,
GTK_RESPONSE_YES,
NULL);
// This is right for the keep changes dialog, but not for the truncation dialog #ifdef TRUNCATE_OLD
// But it is probably time to remove that... I didn't cater to it when migrating from GnomeUIInfo to GtkUIManager and GtkAction // 20210210 need to check if this is still right
gtk_dialog_set_default_response (GTK_DIALOG(dlg), GTK_RESPONSE_YES);
text = gtk_label_new(msg);
gtk_widget_show(text);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), text, TRUE, TRUE, 0);
gtk_widget_show_all(dlg) ;
/*
if (GTK_WIDGET_VISIBLE(file_selector)) {
gtk_window_set_transient_for((GtkWindow*) dlg, (GtkWindow*) file_selector);
}*/
dres = gtk_dialog_run(GTK_DIALOG(dlg));
gtk_widget_destroy(dlg) ;
if (dres == GTK_RESPONSE_NONE || dres == GTK_RESPONSE_CANCEL) {
dres = 2 ; /* return we clicked cancel */
} else if (dres == GTK_RESPONSE_YES) {
dres = 0 ; /* return we clicked yes */
} else {
dres = 1 ;
}
main_redraw(FALSE, TRUE);
return dres;
}
int yesno(char *msg)
{
GtkWidget *dlg, *text;
int dres;
dlg = gtk_dialog_new_with_buttons("Question",
GTK_WINDOW(main_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_NO,
GTK_RESPONSE_NO,
GTK_STOCK_YES,
GTK_RESPONSE_YES,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG(dlg), GTK_RESPONSE_NO);
text = gtk_label_new(msg);
gtk_widget_show(text);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), text, TRUE, TRUE, 0);
/*
if (GTK_WIDGET_VISIBLE(file_selector)) {
gtk_window_set_transient_for((GtkWindow*) dlg, (GtkWindow*) file_selector);
}*/
gtk_widget_show_all(dlg) ;
dres = gtk_dialog_run(GTK_DIALOG(dlg));
gtk_widget_destroy(dlg) ;
if (dres == GTK_RESPONSE_NONE || dres == GTK_RESPONSE_NO) {
dres = 1 ; /* return we clicked no */
} else {
dres = 0 ; /* return we clicked yes */
}
main_redraw(FALSE, TRUE);
return dres;
}
int prompt_user(char *msg, char *s, int maxlen)
{
GtkWidget *dlg, *text, *entry ;
int dres;
dlg = gtk_dialog_new_with_buttons("Input Requested",
GTK_WINDOW(main_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
GTK_STOCK_OK,
GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG(dlg), GTK_RESPONSE_OK);
text = gtk_label_new(msg);
gtk_widget_show(text);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), text, TRUE, TRUE, 0);
entry = gtk_entry_new_with_max_length(maxlen);
gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
if(strlen(s) > 0)
gtk_entry_set_text(GTK_ENTRY(entry), s);
gtk_widget_show(entry);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), entry, TRUE, TRUE, 0);
/*
if (GTK_WIDGET_VISIBLE(file_selector)) {
gtk_window_set_transient_for((GtkWindow*) dlg, (GtkWindow*) file_selector);
}*/
gtk_widget_show_all(dlg) ;
dres = gtk_dialog_run(GTK_DIALOG(dlg));
if (dres == GTK_RESPONSE_NONE || dres == GTK_RESPONSE_NO) {
dres = 1 ; /* return we clicked cancel */
} else {
dres = 0 ; /* return we clicked yes */
strcpy(s, gtk_entry_get_text(GTK_ENTRY(entry)));
}
gtk_widget_destroy(dlg) ;
main_redraw(FALSE, TRUE);
return dres;
}
void help(GtkWidget * widget, gpointer data)
{
/* This shows the help in yelp and requires /usr/share/gnome/help/gwc/C/gwc.html (or similar, if not using html documentation)
#if GTK_CHECK_VERSION(2,14,0)
// GdkScreen *screen;
// Need some more includes or something for this display stuff
// DDisplay *ddisp;
// ddisp = ddisplay_active();
// screen = gtk_widget_get_screen (GTK_WIDGET(ddisp->menu_bar));
// opens /usr/share/gnome/help/gwc/gwc.html (or similar, if not using html documentation)
// if (gtk_show_uri(screen, "ghelp:gwc", gtk_get_current_event_time (), NULL))
if (gtk_show_uri(NULL, "ghelp:gwc", gtk_get_current_event_time (), NULL))
return;
#endif
*/
// We prefer to show the help in a browser than yelp.
// We should probably modify this so that it works if running GWC from the build directory without installing, and/or
// so that it shows a warning message if the help file does not exist. But should figure out test for gvfs first.
char *uri = g_strconcat ("file://", HELPDIR, "/", APPNAME, "/", APPNAME, ".html", NULL);
#ifdef MAC_OS_X
if ( gtkosx_application_get_bundle_id() )
uri = g_strconcat ("file://", g_uri_escape_string(gtkosx_application_get_resource_path(), "/", TRUE), HELPDIR, "/", APPNAME, "/", APPNAME, ".html", NULL);
//g_message("testing %s", uri);
char *command = g_strdup_printf("%s %s &", "open", uri);
system(command);
g_free(command);
// I had compile problems trying to do it using this method!
/* NSURL *ns_url;
gboolean retval;
//neither work
//NSAutoreleasePool *pool [[NSAutoreleasePool alloc] init];
@autoreleasepool
{
ns_url = NSURL URLWithString: [NSString stringWithUTF8String: "file:///users/alister/gwc/doc/gtk-wave-cleaner.html"];
retval = [[NSWorkspace sharedWorkspace] openURL: ns_url];
}
return retval;
*/
# else
/*
// This is infuriating as it silently fails if gvfs is not installed, and it will freeze gwc
// if gvfs is installed but broken (e.g. because the dbus session isn't working correctly)!
if GTK_CHECK_VERSION(2,14,0)
{
// not sure if this does what I want
GdkScreen *screen = gtk_widget_get_screen (main_window);
// First try gtk_show_uri(), which fails if gvfs is not installed
// Then use xdg-open, which should work in almost all cases.
// If we were keen we could copy pragha's src/utils.c, which then tries firefox, mozilla, opera...
if ( !gtk_show_uri(screen, uri, gtk_get_current_event_time (), NULL) )
{
char *command = g_strdup_printf("%s %s &", command ? command : "xdg-open", uri);
system(command);
g_free(command);
}
}
else
{ */
// I used to think that xdg-open was inferior because it used a hard-coded list of browsers,
// but it actually uses the $BROWSER environment variable if set
char *command = g_strdup_printf("%s %s &", "xdg-open", uri);
system(command);
g_free(command);
// }
#endif
g_free(uri);
}
void declick_with_sensitivity(double sensitivity)
{
long first, last;
char *result_msg;
gint leave_click_marks ;
repair_clicks =
gtk_toggle_button_get_active((GtkToggleButton *)detect_only_widget) == TRUE ? FALSE : TRUE;
leave_click_marks =
gtk_toggle_button_get_active((GtkToggleButton *)leave_click_marks_widget) == TRUE ? TRUE : FALSE ;
if (repair_clicks == TRUE)
start_save_undo("Undo declick", &audio_view);
get_region_of_interest(&first, &last, &audio_view);
push_status_text(repair_clicks ==
TRUE ? "Declicking selection" : "Detecting clicks");
click_data.max_clicks = MAX_CLICKS;
result_msg =
do_declick(&prefs, first, last, audio_view.channel_selection_mask,
sensitivity, repair_clicks, &click_data,
declick_iterate_flag,leave_click_marks);
if (repair_clicks == TRUE) {
resample_audio_data(&prefs, first, last);
save_sample_block_data(&prefs);
}
pop_status_text();
set_status_text(result_msg);
if (repair_clicks == TRUE) {
close_undo();
}
main_redraw(FALSE, TRUE);
}
void declick(GtkWidget * widget, gpointer data)
{
if ((file_processing == FALSE) && (file_is_open == TRUE)
&& (audio_playback == FALSE)) {
file_processing = TRUE;
if(declick_detector_type == HPF_DETECT)
declick_with_sensitivity(strong_declick_sensitivity);
else
declick_with_sensitivity(strong_fft_declick_sensitivity);
file_processing = FALSE;
}
}
void declick_weak(GtkWidget * widget, gpointer data)
{
if ((file_processing == FALSE) && (file_is_open == TRUE)
&& (audio_playback == FALSE)) {
file_processing = TRUE;
if(declick_detector_type == HPF_DETECT)
declick_with_sensitivity(weak_declick_sensitivity);
else
declick_with_sensitivity(weak_fft_declick_sensitivity);
file_processing = FALSE;
}
}
void estimate(GtkWidget * widget, gpointer data)
{
if ((file_processing == FALSE) && (file_is_open == TRUE)
&& (audio_playback == FALSE)) {
long first, last;
file_processing = TRUE;
get_region_of_interest(&first, &last, &audio_view);
dethunk(&prefs, first, last, audio_view.channel_selection_mask);
main_redraw(FALSE, TRUE);
file_processing = FALSE;
}
}
void manual_declick(GtkWidget * widget, gpointer data)
{
if ((file_processing == FALSE) && (file_is_open == TRUE)
&& (audio_playback == FALSE)) {
int doit = TRUE;
long first, last;
file_processing = TRUE;
get_region_of_interest(&first, &last, &audio_view);
if (last - first > 299) {
char msg_buf[1000] ;
double n = last-first+1 ;
double a = 100 ;
double elements = (
n +
(n-a) * n +
(n-a) * n +
(n-a) * n +
(n-a) * (n-a) +
(n-a) * (n-a) +
n * n
) ;
double bytes = elements * sizeof(double) / (double) (1 << 20) ;
char *units = "Megabytes" ;
if(bytes > 1000) {
bytes /= (double) 1024 ;
units = "Gigabytes" ;
}
if(bytes > 1000) {
bytes /= (double) 1024 ;
units = "Terabytes" ;
}
sprintf(msg_buf, "Repairing > 300 samples may cause a crash\nYou have selected %lg samples, which will require about %8.0lf %s of memory and a long time.",
n, bytes, units ) ;
doit = FALSE;
if (!yesno(msg_buf))
doit = TRUE;
}
if (doit == TRUE) {
start_save_undo("Undo declick", &audio_view);
push_status_text("Declicking selection");
declick_a_click(&prefs, first, last,
audio_view.channel_selection_mask);
resample_audio_data(&prefs, first, last);
save_sample_block_data(&prefs);
pop_status_text();
set_status_text("Manual declick done.");
close_undo();
main_redraw(FALSE, TRUE);
}
file_processing = FALSE;
}
}
void decrackle(GtkWidget * widget, gpointer data)
{
if ((file_processing == FALSE) && (file_is_open == TRUE)
&& (audio_playback == FALSE)) {
int cancel;
long first, last;
file_processing = TRUE;
push_status_text("Saving undo information");
start_save_undo("Undo decrackle", &audio_view);
get_region_of_interest(&first, &last, &audio_view);
cancel = save_undo_data(first, last, &prefs, TRUE);
close_undo();
pop_status_text();
if (cancel != 1) {
push_status_text("Decrackling selection");
do_decrackle(&prefs, first, last,
audio_view.channel_selection_mask,
decrackle_level, decrackle_window,
decrackle_average);
resample_audio_data(&prefs, first, last);
save_sample_block_data(&prefs);
pop_status_text();
set_status_text("Decrackle done.");
}
main_redraw(FALSE, TRUE);
file_processing = FALSE;
}
}
void noise_sample(GtkWidget * widget, gpointer data)
{
if ((file_processing == FALSE) && (file_is_open == TRUE)
&& (audio_playback == FALSE)) {
file_processing = TRUE;
get_region_of_interest(&denoise_data.noise_start,
&denoise_data.noise_end, &audio_view);
denoise_data.ready = TRUE;
load_denoise_preferences() ;
//print_noise_sample(&prefs, &denoise_prefs, denoise_data.noise_start, denoise_data.noise_end) ;
file_processing = FALSE;
}
}
void remove_noise(GtkWidget * widget, gpointer data)
{
if ((file_processing == FALSE) && (file_is_open == TRUE)
&& (audio_playback == FALSE)) {
file_processing = TRUE;
if (denoise_data.ready == FALSE) {
warning("Please select the noise sample first");
} else {
get_region_of_interest(&denoise_data.denoise_start,
&denoise_data.denoise_end, &audio_view);
load_denoise_preferences();
print_denoise("remove_noise", &denoise_prefs);
{
int cancel;
if (denoise_prefs.FFT_SIZE >
(denoise_data.noise_end - denoise_data.noise_start +
1)) {
warning
("FFT_SIZE must be <= # samples in noise sample!");
main_redraw(FALSE, TRUE);
file_processing = FALSE ;
return;
}
push_status_text("Saving undo information");
start_save_undo("Undo denoise", &audio_view);
cancel =
save_undo_data(denoise_data.denoise_start,
denoise_data.denoise_end, &prefs, TRUE);
close_undo();
pop_status_text();
if (cancel != 1) {
push_status_text("Denoising selection");
denoise(&prefs, &denoise_prefs,
denoise_data.noise_start,
denoise_data.noise_end,
denoise_data.denoise_start,
denoise_data.denoise_end,
audio_view.channel_selection_mask);
resample_audio_data(&prefs, denoise_data.denoise_start,
denoise_data.denoise_end);
save_sample_block_data(&prefs);