mp3splt-gtk: src/options_manager.c Source File

mp3splt-gtk 0.9.3.1519

Loading...
Searching...
No Matches
options_manager.c
Go to the documentation of this file.
1/**********************************************************
2 *
3 * mp3splt-gtk -- utility based on mp3splt,
4 * for mp3/ogg splitting without decoding
5 *
6 * Copyright: (C) 2005-2014 Alexandru Munteanu
7 * Contact: m@ioalex.net
8 *
9 * http://mp3splt.sourceforge.net/
10 *
11 *********************************************************/
12
13/**********************************************************
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
28 * USA.
29 *
30 *********************************************************/
31
32/*!********************************************************
33 * \file
34 * Get the current state of all GUI buttons
35 *
36 * The code contained in this file reads out the current
37 * state of all GUI buttons and saves it into the structure
38 * ui->mp3splt_state.
39 ********************************************************/
40
41#include "options_manager.h"
42#include "ui_types.h"
43
51 void update_output_options(ui_state *ui, gboolean is_checked_output_radio_box, gchar *output_format)
52{
53 if (!is_checked_output_radio_box)
54 {
55 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_OUTPUT_FILENAMES, SPLT_OUTPUT_FORMAT);
56 gint error = mp3splt_set_oformat(ui->mp3splt_state, output_format);
57 print_status_bar_confirmation_in_idle(error, ui);
58 }
59 else
60 {
61 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_OUTPUT_FILENAMES, SPLT_OUTPUT_DEFAULT);
62 }
63}
64
65 ui_for_split *build_ui_for_split(ui_state *ui)
66{
67 gui_state *gui = ui->gui;
68
69 ui_for_split *ui_fs = g_malloc0(sizeof(ui_for_split));
70 ui_fs->ui = ui;
71
72 ui_fs->frame_mode = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gui->frame_mode));
73 ui_fs->bit_reservoir_mode =
74 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gui->bit_reservoir_mode));
75
76 ui_fs->adjust_mode = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gui->adjust_mode));
77 ui_fs->adjust_offset = (float) gtk_spin_button_get_value(GTK_SPIN_BUTTON(gui->spinner_adjust_offset));
78 ui_fs->adjust_gap = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(gui->spinner_adjust_gap));
79 ui_fs->adjust_threshold = (float)
80 gtk_spin_button_get_value(GTK_SPIN_BUTTON(gui->spinner_adjust_threshold));
81 ui_fs->adjust_min = (float) gtk_spin_button_get_value(GTK_SPIN_BUTTON(gui->spinner_adjust_min));
82
83 ui_fs->split_file_mode = get_split_file_mode(ui);
84
85 ui_fs->selected_split_mode = get_selected_split_mode(ui);
86
87 ui_fs->time_split_value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(gui->spinner_time));
88 ui_fs->equal_tracks_value =
89 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(gui->spinner_equal_tracks));
90
91 ui_fs->silence_threshold = (float)
92 gtk_spin_button_get_value(GTK_SPIN_BUTTON(gui->all_spinner_silence_threshold));
93 ui_fs->silence_shots =
94 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(gui->all_spinner_silence_shots));
95 ui_fs->silence_offset = (float)
96 gtk_spin_button_get_value(GTK_SPIN_BUTTON(gui->all_spinner_silence_offset));
97 ui_fs->silence_number =
98 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(gui->all_spinner_silence_number_tracks));
99 ui_fs->silence_minimum_length = (float)
100 gtk_spin_button_get_value(GTK_SPIN_BUTTON(gui->all_spinner_silence_minimum));
101 ui_fs->silence_minimum_track_length = (float)
102 gtk_spin_button_get_value(GTK_SPIN_BUTTON(gui->all_spinner_track_minimum));
103 ui_fs->silence_remove =
104 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gui->all_silence_remove_silence));
105
106 ui_fs->trim_silence_threshold = (float)
107 gtk_spin_button_get_value(GTK_SPIN_BUTTON(gui->all_spinner_trim_silence_threshold));
108
109 ui_fs->single_silence_threshold = ui->infos->silence_threshold_value;
110 ui_fs->single_silence_shots = ui->infos->silence_shots_value;
111 ui_fs->single_silence_offset = ui->infos->silence_offset_value;
112 ui_fs->single_silence_number = ui->infos->silence_number_of_tracks;
113 ui_fs->single_silence_minimum_length = ui->infos->silence_minimum_length;
114 ui_fs->single_silence_minimum_track_length = ui->infos->silence_minimum_track_length;
115 ui_fs->single_silence_remove = ui->infos->silence_remove_silence_between_tracks;
116
117 ui_fs->selected_tags_value = rh_get_active_value(gui->tags_radio);
118 ui_fs->tags_version = get_checked_tags_version_radio_box(gui);
119
120 ui_fs->create_dirs_from_filenames =
121 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gui->create_dirs_from_output_files));
122
123 ui_fs->regex_replace_underscores =
124 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gui->replace_underscore_by_space_check_box));
125 ui_fs->regex_artist_tag_format = ch_get_active_value(gui->artist_text_properties_combo);
126 ui_fs->regex_album_tag_format = ch_get_active_value(gui->album_text_properties_combo);
127 ui_fs->regex_title_tag_format = ch_get_active_value(gui->title_text_properties_combo);
128 ui_fs->regex_comment_tag_format = ch_get_active_value(gui->comment_text_properties_combo);
129
130 const gchar *regex = gtk_entry_get_text(GTK_ENTRY(gui->regex_entry));
131 if (regex != NULL)
132 {
133 ui_fs->regex = g_strdup(regex);
134 }
135
136 const gchar *regex_default_comment = gtk_entry_get_text(GTK_ENTRY(gui->comment_tag_entry));
137 if (regex_default_comment != NULL)
138 {
139 ui_fs->regex_default_comment = g_strdup(regex_default_comment);
140 }
141
142 const gchar *regex_default_genre = ch_get_active_str_value(gui->genre_combo);
143 if (regex_default_genre != NULL)
144 {
145 ui_fs->regex_default_genre = g_strdup(regex_default_genre);
146 }
147
148 const gchar *output_format = gtk_entry_get_text(GTK_ENTRY(ui->gui->output_entry));
149 if (output_format != NULL)
150 {
151 ui_fs->output_format = g_strdup(output_format);
152 }
153
154 const gchar *output_directory = get_output_directory(ui);
155 if (output_directory != NULL)
156 {
157 ui_fs->output_directory = g_strdup(output_directory);
158 }
159
160 ui_fs->is_checked_output_radio_box = get_checked_output_radio_box(ui);
161
162 return ui_fs;
163}
164
165void free_ui_for_split(ui_for_split *ui_fs)
166{
167 if (ui_fs->pat)
168 {
169 free_points_and_tags(&ui_fs->pat);
170 }
171
172 if (ui_fs->regex) { g_free(ui_fs->regex); }
173 if (ui_fs->regex_default_comment) { g_free(ui_fs->regex_default_comment); }
174 if (ui_fs->regex_default_genre) { g_free(ui_fs->regex_default_genre); }
175 if (ui_fs->output_format) { g_free(ui_fs->output_format); }
176 if (ui_fs->output_directory) { g_free(ui_fs->output_directory); }
177 if (ui_fs->test_regex_filename) { g_free(ui_fs->test_regex_filename); }
178
179 g_free(ui_fs);
180}
181
189 void put_options_from_preferences(ui_for_split *ui_fs)
190{
191 ui_state *ui = ui_fs->ui;
192
193 if (ui_fs->frame_mode)
194 {
195 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_FRAME_MODE, SPLT_TRUE);
196 }
197 else
198 {
199 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_FRAME_MODE, SPLT_FALSE);
200 }
201
202 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_HANDLE_BIT_RESERVOIR,
203 ui_fs->bit_reservoir_mode);
204
205 if (ui_fs->adjust_mode)
206 {
207 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_AUTO_ADJUST, SPLT_TRUE);
208 mp3splt_set_float_option(ui->mp3splt_state, SPLT_OPT_PARAM_OFFSET, ui_fs->adjust_offset);
209 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_PARAM_GAP, ui_fs->adjust_gap);
210 mp3splt_set_float_option(ui->mp3splt_state, SPLT_OPT_PARAM_THRESHOLD, ui_fs->adjust_threshold);
211 mp3splt_set_float_option(ui->mp3splt_state, SPLT_OPT_PARAM_MIN_LENGTH, ui_fs->adjust_min);
212 }
213 else
214 {
215 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_AUTO_ADJUST, SPLT_FALSE);
216 }
217
218 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_INPUT_NOT_SEEKABLE, SPLT_FALSE);
219 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_NORMAL_MODE);
220
221 if (ui_fs->split_file_mode == FILE_MODE_SINGLE)
222 {
223 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_NORMAL_MODE);
224 }
225 else
226 {
227 switch (ui_fs->selected_split_mode)
228 {
229 case SELECTED_SPLIT_NORMAL:
230 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_NORMAL_MODE);
231 break;
232 case SELECTED_SPLIT_WRAP:
233 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_WRAP_MODE);
234 break;
235 case SELECTED_SPLIT_TIME:
236 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_TIME_MODE);
237 mp3splt_set_long_option(ui->mp3splt_state, SPLT_OPT_SPLIT_TIME,
238 ui_fs->time_split_value * 100);
239 break;
240 case SELECTED_SPLIT_EQUAL_TIME_TRACKS:
241 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_LENGTH_MODE);
242 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_LENGTH_SPLIT_FILE_NUMBER,
243 ui_fs->equal_tracks_value);
244 break;
245 case SELECTED_SPLIT_SILENCE:
246 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_SILENCE_MODE);
247 mp3splt_set_float_option(ui->mp3splt_state, SPLT_OPT_PARAM_THRESHOLD,
248 ui_fs->silence_threshold);
249 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_PARAM_SHOTS, ui_fs->silence_shots);
250 mp3splt_set_float_option(ui->mp3splt_state, SPLT_OPT_PARAM_OFFSET, ui_fs->silence_offset);
251 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_PARAM_NUMBER_TRACKS,
252 ui_fs->silence_number);
253 mp3splt_set_float_option(ui->mp3splt_state, SPLT_OPT_PARAM_MIN_LENGTH,
254 ui_fs->silence_minimum_length);
255 mp3splt_set_float_option(ui->mp3splt_state, SPLT_OPT_PARAM_MIN_TRACK_LENGTH,
256 ui_fs->silence_minimum_track_length);
257 if (ui_fs->silence_remove)
258 {
259 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_PARAM_REMOVE_SILENCE, SPLT_TRUE);
260 }
261 else
262 {
263 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_PARAM_REMOVE_SILENCE, SPLT_FALSE);
264 }
265 break;
266 case SELECTED_SPLIT_TRIM_SILENCE:
267 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_TRIM_SILENCE_MODE);
268 mp3splt_set_float_option(ui->mp3splt_state, SPLT_OPT_PARAM_THRESHOLD, ui_fs->trim_silence_threshold);
269 break;
270 case SELECTED_SPLIT_ERROR:
271 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_ERROR_MODE);
272 break;
273 default:
274 break;
275 }
276 }
277
278 int selected_tags_value = ui_fs->selected_tags_value;;
279 if (selected_tags_value == NO_TAGS)
280 {
281 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_TAGS, SPLT_NO_TAGS);
282 }
283 else if (selected_tags_value == DEFAULT_TAGS)
284 {
285 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_TAGS, SPLT_CURRENT_TAGS);
286 }
287 else if (selected_tags_value == ORIGINAL_FILE_TAGS)
288 {
289 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_TAGS, SPLT_TAGS_ORIGINAL_FILE);
290 }
291 else if (selected_tags_value == TAGS_FROM_FILENAME)
292 {
293 put_tags_from_filename_regex_options(ui_fs);
294 }
295
296 int tags_radio_choice = ui_fs->tags_version;
297 if (tags_radio_choice == 0)
298 {
299 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_FORCE_TAGS_VERSION, 0);
300 }
301 else if (tags_radio_choice == 1)
302 {
303 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_FORCE_TAGS_VERSION, 1);
304 }
305 else if (tags_radio_choice == 2)
306 {
307 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_FORCE_TAGS_VERSION, 2);
308 }
309 else if (tags_radio_choice == 3)
310 {
311 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_FORCE_TAGS_VERSION, 12);
312 }
313
314 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_CREATE_DIRS_FROM_FILENAMES,
315 ui_fs->create_dirs_from_filenames);
316}
317
318void put_tags_from_filename_regex_options(ui_for_split *ui_fs)
319{
320 ui_state *ui = ui_fs->ui;
321
322 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_TAGS, SPLT_TAGS_FROM_FILENAME_REGEX);
323
324 int underscores = ui_fs->regex_replace_underscores;
325 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_REPLACE_UNDERSCORES_TAG_FORMAT, underscores);
326
327 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_ARTIST_TAG_FORMAT,
328 ui_fs->regex_artist_tag_format);
329 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_ALBUM_TAG_FORMAT,
330 ui_fs->regex_album_tag_format);
331 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_TITLE_TAG_FORMAT,
332 ui_fs->regex_title_tag_format);
333 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_COMMENT_TAG_FORMAT,
334 ui_fs->regex_comment_tag_format);
335
336 mp3splt_set_input_filename_regex(ui->mp3splt_state, ui_fs->regex);
337
338 const gchar *default_comment = ui_fs->regex_default_comment;
339 if (strlen(default_comment) == 0)
340 {
341 default_comment = NULL;
342 }
343 mp3splt_set_default_comment_tag(ui->mp3splt_state, default_comment);
344
345 mp3splt_set_default_genre_tag(ui->mp3splt_state, ui_fs->regex_default_genre);
346}
347
update_output_options
void update_output_options(ui_state *ui, gboolean is_checked_output_radio_box, gchar *output_format)
Update the output options.
Definition options_manager.c:51
put_options_from_preferences
void put_options_from_preferences(ui_for_split *ui_fs)
Update the ui->mp3splt_state structure.
Definition options_manager.c:189
get_output_directory
gchar * get_output_directory(ui_state *ui)
Get the name of the output directory.
Definition preferences_window.c:189
get_checked_output_radio_box
gboolean get_checked_output_radio_box(ui_state *ui)
returns the checked output radio box
Definition preferences_window.c:71
get_checked_tags_version_radio_box
gint get_checked_tags_version_radio_box(gui_state *gui)
returns the checked tags radio box
Definition preferences_window.c:90
gui_state
Definition ui_types.h:227
ui_for_split
Definition ui_types.h:571
ui_state
Definition ui_types.h:509