mp3splt-gtk

- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

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-2013 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
50 void update_output_options(ui_state *ui)
51 {
52 lock_mutex(&ui->variables_mutex);
53 mp3splt_set_filename_to_split(ui->mp3splt_state, get_input_filename(ui->gui));
54 unlock_mutex(&ui->variables_mutex);
55
56 if (get_checked_output_radio_box(ui) == 0)
57 {
58 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_OUTPUT_FILENAMES, SPLT_OUTPUT_FORMAT);
59 const char *data = gtk_entry_get_text(GTK_ENTRY(ui->gui->output_entry));
60 gint error = mp3splt_set_oformat(ui->mp3splt_state, data);
61 print_status_bar_confirmation(error, ui);
62 }
63 else
64 {
65 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_OUTPUT_FILENAMES, SPLT_OUTPUT_DEFAULT);
66 }
67 }
68
76 void put_options_from_preferences(ui_state *ui)
77 {
78 gui_state *gui = ui->gui;
79
80 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gui->frame_mode)))
81 {
82 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_FRAME_MODE, SPLT_TRUE);
83 }
84 else
85 {
86 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_FRAME_MODE, SPLT_FALSE);
87 }
88
89 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gui->adjust_mode)))
90 {
91 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_AUTO_ADJUST, SPLT_TRUE);
92 mp3splt_set_float_option(ui->mp3splt_state, SPLT_OPT_PARAM_OFFSET,
93 gtk_spin_button_get_value(GTK_SPIN_BUTTON(gui->spinner_adjust_offset)));
94 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_PARAM_GAP,
95 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(gui->spinner_adjust_gap)));
96 mp3splt_set_float_option(ui->mp3splt_state, SPLT_OPT_PARAM_THRESHOLD,
97 gtk_spin_button_get_value(GTK_SPIN_BUTTON(gui->spinner_adjust_threshold)));
98 mp3splt_set_float_option(ui->mp3splt_state, SPLT_OPT_PARAM_MIN_LENGTH,
99 gtk_spin_button_get_value(GTK_SPIN_BUTTON(gui->spinner_adjust_min)));
100 }
101 else
102 {
103 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_AUTO_ADJUST, SPLT_FALSE);
104 }
105
106 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_INPUT_NOT_SEEKABLE, SPLT_FALSE);
107 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_NORMAL_MODE);
108
109 if (get_split_file_mode_safe(ui) == FILE_MODE_SINGLE)
110 {
111 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_NORMAL_MODE);
112 }
113 else
114 {
115 switch (get_selected_split_mode_safe(ui))
116 {
117 case SELECTED_SPLIT_NORMAL:
118 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_NORMAL_MODE);
119 break;
120 case SELECTED_SPLIT_WRAP:
121 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_WRAP_MODE);
122 break;
123 case SELECTED_SPLIT_TIME:
124 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_TIME_MODE);
125 mp3splt_set_long_option(ui->mp3splt_state, SPLT_OPT_SPLIT_TIME,
126 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(gui->spinner_time)) * 100);
127 break;
128 case SELECTED_SPLIT_EQUAL_TIME_TRACKS:
129 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_LENGTH_MODE);
130 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_LENGTH_SPLIT_FILE_NUMBER,
131 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(gui->spinner_equal_tracks)));
132 break;
133 case SELECTED_SPLIT_SILENCE:
134 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_SILENCE_MODE);
135 mp3splt_set_float_option(ui->mp3splt_state, SPLT_OPT_PARAM_THRESHOLD,
136 gtk_spin_button_get_value(GTK_SPIN_BUTTON(gui->all_spinner_silence_threshold)));
137 mp3splt_set_float_option(ui->mp3splt_state, SPLT_OPT_PARAM_OFFSET,
138 gtk_spin_button_get_value(GTK_SPIN_BUTTON(gui->all_spinner_silence_offset)));
139 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_PARAM_NUMBER_TRACKS,
140 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(gui->all_spinner_silence_number_tracks)));
141 mp3splt_set_float_option(ui->mp3splt_state, SPLT_OPT_PARAM_MIN_LENGTH,
142 gtk_spin_button_get_value(GTK_SPIN_BUTTON(gui->all_spinner_silence_minimum)));
143 mp3splt_set_float_option(ui->mp3splt_state, SPLT_OPT_PARAM_MIN_TRACK_LENGTH,
144 gtk_spin_button_get_value(GTK_SPIN_BUTTON(gui->all_spinner_track_minimum)));
145 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gui->all_silence_remove_silence)))
146 {
147 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_PARAM_REMOVE_SILENCE, SPLT_TRUE);
148 }
149 else
150 {
151 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_PARAM_REMOVE_SILENCE, SPLT_FALSE);
152 }
153 break;
154 case SELECTED_SPLIT_TRIM_SILENCE:
155 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_TRIM_SILENCE_MODE);
156 mp3splt_set_float_option(ui->mp3splt_state, SPLT_OPT_PARAM_THRESHOLD,
157 gtk_spin_button_get_value(GTK_SPIN_BUTTON(gui->all_spinner_trim_silence_threshold)));
158 break;
159 case SELECTED_SPLIT_ERROR:
160 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_ERROR_MODE);
161 break;
162 default:
163 break;
164 }
165 }
166
167 gint selected_tags_value = rh_get_active_value(gui->tags_radio);
168 if (selected_tags_value == NO_TAGS)
169 {
170 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_TAGS, SPLT_NO_TAGS);
171 }
172 else if (selected_tags_value == DEFAULT_TAGS)
173 {
174 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_TAGS, SPLT_CURRENT_TAGS);
175 }
176 else if (selected_tags_value == ORIGINAL_FILE_TAGS)
177 {
178 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_TAGS, SPLT_TAGS_ORIGINAL_FILE);
179 }
180 else if (selected_tags_value == TAGS_FROM_FILENAME)
181 {
182 put_tags_from_filename_regex_options(ui);
183 }
184
185 gint tags_radio_choice = get_checked_tags_version_radio_box(gui);
186 if (tags_radio_choice == 0)
187 {
188 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_FORCE_TAGS_VERSION, 0);
189 }
190 else if (tags_radio_choice == 1)
191 {
192 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_FORCE_TAGS_VERSION, 1);
193 }
194 else if (tags_radio_choice == 2)
195 {
196 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_FORCE_TAGS_VERSION, 2);
197 }
198 else if (tags_radio_choice == 3)
199 {
200 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_FORCE_TAGS_VERSION, 12);
201 }
202
203 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_CREATE_DIRS_FROM_FILENAMES,
204 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gui->create_dirs_from_output_files)));
205 }
206
207 void put_tags_from_filename_regex_options(ui_state *ui)
208 {
209 gui_state *gui = ui->gui;
210
211 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_TAGS, SPLT_TAGS_FROM_FILENAME_REGEX);
212
213 gint underscores =
214 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gui->replace_underscore_by_space_check_box));
215 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_REPLACE_UNDERSCORES_TAG_FORMAT, underscores);
216
217 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_ARTIST_TAG_FORMAT,
218 ch_get_active_value(gui->artist_text_properties_combo));
219 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_ALBUM_TAG_FORMAT,
220 ch_get_active_value(gui->album_text_properties_combo));
221 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_TITLE_TAG_FORMAT,
222 ch_get_active_value(gui->title_text_properties_combo));
223 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_COMMENT_TAG_FORMAT,
224 ch_get_active_value(gui->comment_text_properties_combo));
225
226 const gchar *regular_expression = gtk_entry_get_text(GTK_ENTRY(gui->regex_entry));
227 mp3splt_set_input_filename_regex(ui->mp3splt_state, regular_expression);
228
229 const gchar *default_comment = gtk_entry_get_text(GTK_ENTRY(gui->comment_tag_entry));
230 if (strlen(default_comment) == 0)
231 {
232 default_comment = NULL;
233 }
234 mp3splt_set_default_comment_tag(ui->mp3splt_state, default_comment);
235
236 mp3splt_set_default_genre_tag(ui->mp3splt_state, ch_get_active_str_value(gui->genre_combo));
237 }
238
update_output_options
void update_output_options(ui_state *ui)
Update the output options.
Definition: options_manager.c:50
get_input_filename
gchar * get_input_filename(gui_state *gui)
Get the name of the input file.
Definition: main_window.c:76
print_status_bar_confirmation
void print_status_bar_confirmation(gint error, ui_state *ui)
Output an error message from libmp3splt to the status bar.
Definition: main_window.c:1115
ui_state
Definition: ui_types.h:485
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
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
put_options_from_preferences
void put_options_from_preferences(ui_state *ui)
Update the ui-&gt;mp3splt_state structure.
Definition: options_manager.c:76
gui_state
Definition: ui_types.h:202