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