mp3splt-gtk 0.9.2
Loading...
Searching...
No Matches
ui_manager.c
1/**********************************************************
2 *
3 * mp3splt-gtk -- utility based on mp3splt,
4 * for mp3/ogg splitting without decoding
5 *
6 * Copyright (c) 2005-2014 Alexandru Munteanu - m@ioalex.net
7 *
8 * http://mp3splt.sourceforge.net/
9 *
10 *********************************************************/
11
12/**********************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
27 * USA.
28 *
29 *********************************************************/
30
31#include "ui_manager.h"
32
33static void ui_main_window_new(ui_infos *infos);
34static void ui_infos_new(ui_state *ui);
35static gui_status *ui_status_new();
36static gui_state *ui_gui_new();
37static player_infos *ui_player_infos_new();
38
39static void ui_main_window_free(ui_main_window **main_win);
40static void ui_infos_free(ui_infos **infos);
41static void ui_status_free(gui_status **status);
42static void ui_gui_free(gui_state **gui);
43static void ui_player_infos_free(player_infos **pi);
44
45void ui_set_browser_directory(ui_state *ui, const gchar *directory)
46{
47 ui_infos *infos = ui->infos;
48
49 if (infos->browser_directory)
50 {
51 g_free(infos->browser_directory);
52 infos->browser_directory = NULL;
53 }
54
55 if (directory == NULL)
56 {
57 infos->browser_directory = NULL;
58 return;
59 }
60
61 infos->browser_directory = g_strdup(directory);
62}
63
64const gchar *ui_get_browser_directory(ui_state *ui)
65{
66 return ui->infos->browser_directory;
67}
68
69void ui_set_main_win_position(ui_state *ui, gint x, gint y)
70{
71 if (x == 0 && y == 0)
72 {
73 return;
74 }
75
76 ui_main_window *main_win = ui->infos->main_win;
77 main_win->root_x_pos = x;
78 main_win->root_y_pos = y;
79}
80
81void ui_set_main_win_size(ui_state *ui, gint width, gint height)
82{
83 ui_main_window *main_win = ui->infos->main_win;
84 main_win->width = width;
85 main_win->height = height;
86}
87
88const ui_main_window *ui_get_main_window_infos(ui_state *ui)
89{
90 return ui->infos->main_win;
91}
92
93ui_state *ui_state_new()
94{
95 ui_state *ui = g_malloc0(sizeof(ui_state));
96
97 ui_infos_new(ui);
98 ui->preferences = pm_state_new();
99
100 gint error = SPLT_OK;
101 ui->mp3splt_state = mp3splt_new_state(&error);
102 if (error < 0)
103 {
104 ui_fail(ui, "mp3splt state initialization failed\n", NULL);
105 }
106
107 ui->splitpoints = g_array_new(FALSE, FALSE, sizeof(Split_point));
108 ui->files_to_split = NULL;
109
110 ui->status = ui_status_new();
111 ui->gui = ui_gui_new();
112 ui->pi = ui_player_infos_new();
113
114 ui->return_code = EXIT_SUCCESS;
115
116 init_mutex(&ui->variables_mutex);
117
118 ui->importing_cue_from_configuration_directory = FALSE;
119
120 return ui;
121}
122
123void ui_state_free(ui_state *ui)
124{
125 if (!ui) { return; }
126
127 ui_infos_free(&ui->infos);
128 pm_free(&ui->preferences);
129
130 if (ui->mp3splt_state)
131 {
132 mp3splt_free_state(ui->mp3splt_state);
133 }
134
135 g_array_free(ui->splitpoints, TRUE);
136
137 ui_status_free(&ui->status);
138 ui_gui_free(&ui->gui);
139 ui_player_infos_free(&ui->pi);
140
141 clear_mutex(&ui->variables_mutex);
142
143 g_free(ui);
144}
145
146void ui_register_spinner_int_preference(gchar *main_key, gchar *second_key,
147 gint default_value, GtkWidget *spinner,
148 void (*update_spinner_value_cb)(GtkWidget *spinner, gpointer data),
149 gpointer user_data_for_cb, ui_state *ui)
150{
151 pm_register_spinner_int_preference(main_key, second_key,
152 default_value, spinner, update_spinner_value_cb, user_data_for_cb, ui->preferences);
153}
154
155void ui_register_range_preference(gchar *main_key, gchar *second_key,
156 gint default_value, GtkWidget *range,
157 void (*update_adjustment_value)(GtkAdjustment *adjustment, gpointer data),
158 gpointer user_data_for_cb, ui_state *ui)
159{
160 pm_register_range_preference(main_key, second_key,
161 default_value, range, update_adjustment_value, user_data_for_cb, ui->preferences);
162}
163
164void ui_load_preferences(ui_state *ui)
165{
167}
168
169void ui_save_preferences(GtkWidget *dummy_widget, ui_state *ui)
170{
171 save_preferences(ui);
172}
173
174void ui_fail(ui_state *ui, const gchar *message, ...)
175{
176 if (message != NULL)
177 {
178 gchar formatted_message[1024] = { '\0' };
179
180 va_list ap;
181 va_start(ap, message);
182 g_vsnprintf(formatted_message, 1024, message, ap);
183 va_end(ap);
184
185 fprintf(stderr, "%s", formatted_message);
186 fflush(stderr);
187 }
188
189 ui->return_code = EXIT_FAILURE;
190
191 ui_state_free(ui);
192
193 exit(1);
194}
195
196static void ui_main_window_new(ui_infos *infos)
197{
198 ui_main_window *main_win = g_malloc0(sizeof(ui_main_window));
199
200 main_win->root_x_pos = 0;
201 main_win->root_y_pos = 0;
202
203 main_win->width = UI_DEFAULT_WIDTH;
204 main_win->height = UI_DEFAULT_HEIGHT;
205
206 infos->main_win = main_win;
207}
208
209static void ui_infos_new(ui_state *ui)
210{
211 ui_infos *infos = g_malloc0(sizeof(ui_infos));
212
213 ui_main_window_new(infos);
214
215 infos->browser_directory = NULL;
216 infos->text_options_list = NULL;
217
218 infos->silence_points = NULL;
219 infos->malloced_num_of_silence_points = 0;
220 infos->number_of_silence_points = 0;
221
222 infos->player_seconds = 0;
223 infos->player_minutes = 0;
224 infos->player_hundr_secs = 0;
225 infos->player_seconds2 = 0;
226 infos->player_minutes2 = 0;
227 infos->player_hundr_secs2 = 0;
228
229 infos->total_time = 0;
230 infos->current_time = 0;
231
232 infos->splitnumber = 0;
233 infos->width_drawing_area = 0;
234 infos->zoom_coeff = 2.0;
235 infos->zoom_coeff_old = 2.0;
236
237 infos->hundr_secs_th = 20;
238 infos->tens_of_secs_th = 3 * 100;
239 infos->secs_th = 40 * 100;
240 infos->ten_secs_th = 3 * 6000;
241 infos->minutes_th = 20 * 6000;
242 infos->ten_minutes_th = 3 * 3600 * 100;
243
244 infos->one_minute_time = 1 * 6000;
245 infos->three_minutes_time = 3 * 6000;
246 infos->six_minutes_time = 6 * 6000;
247 infos->ten_minutes_time = 10 * 6000;
248 infos->twenty_minutes_time = 20 * 6000;
249 infos->fourty_minutes_time = 40 * 6000;
250
251 GArray *preview_time_windows = g_array_new(TRUE, TRUE, sizeof(gint));
252 g_array_append_val(preview_time_windows, infos->one_minute_time);
253 g_array_append_val(preview_time_windows, infos->three_minutes_time);
254 g_array_append_val(preview_time_windows, infos->six_minutes_time);
255 g_array_append_val(preview_time_windows, infos->ten_minutes_time);
256 g_array_append_val(preview_time_windows, infos->twenty_minutes_time);
257 g_array_append_val(preview_time_windows, infos->fourty_minutes_time);
258 infos->preview_time_windows = preview_time_windows;
259
260 infos->filtered_points_presence = NULL;
261 infos->silence_wave_number_of_points_threshold = DEFAULT_SILENCE_WAVE_NUMBER_OF_POINTS_THRESHOLD;
262
263 infos->selected_player = PLAYER_GSTREAMER;
264
265 infos->douglas_peucker_thresholds_defaults[0] = 2.0;
266 infos->douglas_peucker_thresholds_defaults[1] = 5.0;
267 infos->douglas_peucker_thresholds_defaults[2] = 8.0;
268 infos->douglas_peucker_thresholds_defaults[3] = 10.0;
269 infos->douglas_peucker_thresholds_defaults[4] = 12.0;
270 infos->douglas_peucker_thresholds_defaults[5] = 15.0;
271
272 infos->douglas_peucker_thresholds[0] = infos->douglas_peucker_thresholds_defaults[0];
273 infos->douglas_peucker_thresholds[1] = infos->douglas_peucker_thresholds_defaults[1];
274 infos->douglas_peucker_thresholds[2] = infos->douglas_peucker_thresholds_defaults[2];
275 infos->douglas_peucker_thresholds[3] = infos->douglas_peucker_thresholds_defaults[3];
276 infos->douglas_peucker_thresholds[4] = infos->douglas_peucker_thresholds_defaults[4];
277 infos->douglas_peucker_thresholds[5] = infos->douglas_peucker_thresholds_defaults[5];
278
279 infos->debug_is_active = FALSE;
280
281 infos->silence_threshold_value = SPLT_DEFAULT_PARAM_THRESHOLD;
282 infos->silence_offset_value = SPLT_DEFAULT_PARAM_OFFSET;
283 infos->silence_number_of_tracks = SPLT_DEFAULT_PARAM_TRACKS;
284 infos->silence_minimum_length = SPLT_DEFAULT_PARAM_MINIMUM_LENGTH;
285 infos->silence_minimum_track_length = SPLT_DEFAULT_PARAM_MINIMUM_TRACK_LENGTH;
286 infos->silence_remove_silence_between_tracks = FALSE;
287
288 infos->freedb_table_number = 0;
289 infos->freedb_selected_id = -1;
290
291 infos->playlist_tree_number = 0;
292 infos->multiple_files_tree_number = 0;
293
294 infos->freedb_search_results = NULL;
295
296 infos->split_file_mode = FILE_MODE_SINGLE;
297
298 infos->outputdirname = NULL;
299
300 gint i = 0;
301 for (i = 0; i < 6;i++)
302 {
303 infos->preview_indexes[i].index = 0;
304 infos->preview_indexes[i].data = NULL;
305 }
306
307 infos->timeout_value = DEFAULT_TIMEOUT_VALUE;
308
309 infos->gstreamer_stop_before_end = DEFAULT_GSTREAMER_STOP_BEFORE_END_VALUE;
310
311 infos->small_seek_jump_value = DEFAULT_SMALL_SEEK_JUMP_VALUE;
312 infos->seek_jump_value = DEFAULT_SEEK_JUMP_VALUE;
313 infos->big_seek_jump_value = DEFAULT_BIG_SEEK_JUMP_VALUE;
314
315 infos->previous_export_thread = NULL;
316
317 infos->previous_mark_time = 0;
318 infos->previous_mark_pixel = 0.0;
319 infos->pixels_diff_regarding_previous = -1;
320 infos->accumulated_diff = 0.0;
321 infos->previous_pixel_by_time =
322 g_hash_table_new_full(g_double_hash, g_double_equal, g_free, g_free);
323 infos->pixel_moved_by_time =
324 g_hash_table_new_full(g_double_hash, g_double_equal, g_free, g_free);
325
326 infos->drawing_preferences_silence_wave = SPLT_FALSE;
327
328 ui->infos = infos;
329}
330
331static gui_status *ui_status_new(ui_state *ui)
332{
333 gui_status *status = g_malloc0(sizeof(gui_status));
334
335 status->splitting = FALSE;
336 status->process_in_progress = 0;
337 status->mouse_on_progress_bar = FALSE;
338
339 status->currently_compute_douglas_peucker_filters = FALSE;
340 status->show_silence_wave = FALSE;
341
342 status->playing = FALSE;
343 status->timer_active = FALSE;
344 status->quick_preview_end_splitpoint = -1;
345 status->preview_start_splitpoint = -1;
346 status->stop_preview_right_after_start = FALSE;
347
348 status->move_time = 0;
349
350 status->button1_pressed = FALSE;
351 status->button2_pressed = FALSE;
352
353 status->quick_preview = FALSE;
354
355 status->button_x = 0;
356 status->button_x2 = 0;
357 status->button_y = 0;
358 status->button_y2 = 0;
359
360 status->move_splitpoints = FALSE;
361 status->splitpoint_to_move = -1;
362 status->remove_splitpoints = FALSE;
363 status->select_splitpoints = FALSE;
364 status->check_splitpoint = FALSE;
365
366 status->first_splitpoint_selected = -1;
367
368 status->spin_mins = 0;
369 status->spin_secs = 0;
370 status->spin_hundr_secs = 0;
371
372 g_snprintf(status->current_description, 255, "%s", _("description here"));
373
374 status->preview_start_position = 0;
375 status->timeout_id = 0;
376
377 status->currently_scanning_for_silence = FALSE;
378
379 status->filename_to_split = NULL;
380
381 status->douglas_callback_counter = 0;
382
383 status->stream = FALSE;
384 status->only_press_pause = FALSE;
385
386 status->change_volume = TRUE;
387 status->on_the_volume_button = FALSE;
388 status->file_browsed = FALSE;
389
390 status->preview_row = 0;
391 status->selected_split_mode = SELECTED_SPLIT_NORMAL;
392
393 status->file_selection_changed = FALSE;
394
395 status->stop_split = FALSE;
396
397 status->previous_zoom_coeff = -2;
398 status->previous_interpolation_level = -2;
399
400 return status;
401}
402
403static player_infos *ui_player_infos_new()
404{
405 player_infos *pi = g_malloc0(sizeof(player_infos));
406
407#ifndef NO_GSTREAMER
408 pi->song_artist = NULL;
409 pi->song_title = NULL;
410 pi->rate = 0;
411 pi->play = NULL;
412 pi->bus = NULL;
413 pi->_gstreamer_is_running = FALSE;
414#endif
415
416#ifndef NO_AUDACIOUS
417 pi->dbus_proxy = NULL;
418 pi->dbus_connection = NULL;
419#endif
420
421 //snackamp
422 pi->in = NULL;
423 pi->out = NULL;
424 pi->connected = FALSE;
425
426 return pi;
427}
428
429static gui_state *ui_gui_new()
430{
431 gui_state *gui = g_malloc0(sizeof(gui_state));
432
433 gui->margin = 4;
434 gui->real_erase_split_length = 12;
435 gui->real_move_split_length = 16;
436 gui->real_checkbox_length = 12;
437 gui->real_wave_length = 96;
438
439 gui->splitpoints_window = NULL;
440 gui->preferences_window = NULL;
441 gui->split_files_window = NULL;
442 gui->freedb_window = NULL;
443
444 return gui;
445}
446
447static void ui_main_window_free(ui_main_window **main_win)
448{
449 if (!main_win || !*main_win)
450 {
451 return;
452 }
453
454 g_free(*main_win);
455 *main_win = NULL;
456}
457
458static void ui_infos_free(ui_infos **infos)
459{
460 if (!infos || !*infos)
461 {
462 return;
463 }
464
465 ui_main_window_free(&(*infos)->main_win);
466
467 if ((*infos)->browser_directory)
468 {
469 g_free((*infos)->browser_directory);
470 (*infos)->browser_directory = NULL;
471 }
472
473 if ((*infos)->text_options_list)
474 {
475 g_list_free((*infos)->text_options_list);
476 }
477
478 if ((*infos)->silence_points)
479 {
480 g_free((*infos)->silence_points);
481 (*infos)->silence_points = NULL;
482 (*infos)->number_of_silence_points = 0;
483 }
484
485 if ((*infos)->previous_pixel_by_time != NULL)
486 {
487 g_hash_table_destroy((*infos)->previous_pixel_by_time);
488 (*infos)->previous_pixel_by_time = NULL;
489 }
490
491 if ((*infos)->pixel_moved_by_time != NULL)
492 {
493 g_hash_table_destroy((*infos)->pixel_moved_by_time);
494 (*infos)->pixel_moved_by_time = NULL;
495 }
496
497 g_array_free((*infos)->preview_time_windows, TRUE);
498
499 g_free(*infos);
500 *infos = NULL;
501}
502
503static void ui_status_free(gui_status **status)
504{
505 if (!status || !*status)
506 {
507 return;
508 }
509
510 g_free(*status);
511 *status = NULL;
512}
513
514static void ui_player_infos_free(player_infos **pi)
515{
516 if (!pi || !*pi)
517 {
518 return;
519 }
520
521 g_free(*pi);
522 *pi = NULL;
523}
524
525static void ui_gui_free(gui_state **gui)
526{
527 if (!gui|| !*gui)
528 {
529 return;
530 }
531
532 g_free(*gui);
533 *gui = NULL;
534}
535
void load_preferences(ui_state *ui)
Read the preferences from the preferences file.