mp3splt-gtk
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-2012 Alexandru Munteanu
7  * Contact: io_fx@yahoo.fr
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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  * the_state.
39  ********************************************************/
40 
41 #include <string.h>
42 
43 #include <gtk/gtk.h>
44 #include <glib/gi18n.h>
45 
46 #include <libmp3splt/mp3splt.h>
47 
48 #include "util.h"
49 #include "player_tab.h"
50 #include "freedb_tab.h"
51 #include "main_win.h"
52 #include "preferences_tab.h"
53 #include "special_split.h"
54 #include "player_tab.h"
55 #include "combo_helper.h"
56 #include "options_manager.h"
57 #include "radio_helper.h"
58 
59 extern gint debug_is_active;
60 
61 extern splt_state *the_state;
62 
63 extern GtkWidget *output_entry;
64 extern gchar *filename_to_split;
65 extern gint selected_split_mode;
66 
67 extern GtkWidget *frame_mode;
68 extern GtkWidget *adjust_mode;
69 extern GtkWidget *spinner_adjust_gap;
70 extern GtkWidget *spinner_adjust_offset;
71 extern GtkWidget *spinner_adjust_threshold;
72 extern GtkWidget *spinner_time;
73 extern GtkWidget *spinner_equal_tracks;
74 extern GtkWidget *create_dirs_from_output_files;
75 
76 extern GtkWidget *all_spinner_silence_number_tracks;
77 extern GtkWidget *all_spinner_silence_minimum;
78 extern GtkWidget *all_spinner_track_minimum;
79 extern GtkWidget *all_spinner_silence_offset;
80 extern GtkWidget *all_spinner_silence_threshold;
81 extern GtkWidget *all_spinner_trim_silence_threshold;
82 extern GtkWidget *all_silence_remove_silence;
83 
84 extern GList *text_options_list;
86 extern GtkComboBox *artist_text_properties_combo;
87 extern GtkComboBox *album_text_properties_combo;
88 extern GtkComboBox *title_text_properties_combo;
89 extern GtkComboBox *comment_text_properties_combo;
90 extern GtkComboBox *genre_combo;
91 extern GtkWidget *comment_tag_entry;
92 extern GtkWidget *regex_entry;
93 
94 extern GtkWidget *tags_radio;
95 
104 {
105  filename_to_split = inputfilename_get();
106  mp3splt_set_filename_to_split(the_state, filename_to_split);
107 
108  if (get_checked_output_radio_box() == 0)
109  {
110  mp3splt_set_int_option(the_state, SPLT_OPT_OUTPUT_FILENAMES,
112 
113  const char *data = gtk_entry_get_text(GTK_ENTRY(output_entry));
114  gint error = SPLT_OUTPUT_FORMAT_OK;
115  mp3splt_set_oformat(the_state, data, &error);
117  }
118  else
119  {
120  mp3splt_set_int_option(the_state, SPLT_OPT_OUTPUT_FILENAMES,
122  }
123 
124  mp3splt_set_int_option(the_state, SPLT_OPT_DEBUG_MODE, debug_is_active);
125 }
126 
135 {
136  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(frame_mode)))
137  {
138  mp3splt_set_int_option(the_state, SPLT_OPT_FRAME_MODE, SPLT_TRUE);
139  }
140  else
141  {
142  mp3splt_set_int_option(the_state, SPLT_OPT_FRAME_MODE, SPLT_FALSE);
143  }
144 
145  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(adjust_mode)))
146  {
147  mp3splt_set_int_option(the_state, SPLT_OPT_AUTO_ADJUST, SPLT_TRUE);
148  mp3splt_set_float_option(the_state, SPLT_OPT_PARAM_OFFSET,
149  gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinner_adjust_offset)));
150  mp3splt_set_int_option(the_state, SPLT_OPT_PARAM_GAP,
151  gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner_adjust_gap)));
152  mp3splt_set_float_option(the_state, SPLT_OPT_PARAM_THRESHOLD,
153  gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinner_adjust_threshold)));
154  }
155  else
156  {
157  mp3splt_set_int_option(the_state, SPLT_OPT_AUTO_ADJUST, SPLT_FALSE);
158  }
159 
160  mp3splt_set_int_option(the_state, SPLT_OPT_INPUT_NOT_SEEKABLE, SPLT_FALSE);
161 
162  mp3splt_set_int_option(the_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_NORMAL_MODE);
163 
164  switch (selected_split_mode)
165  {
166  case SELECTED_SPLIT_NORMAL:
167  mp3splt_set_int_option(the_state, SPLT_OPT_SPLIT_MODE,
169  break;
170  case SELECTED_SPLIT_WRAP:
171  mp3splt_set_int_option(the_state, SPLT_OPT_SPLIT_MODE,
173  break;
174  case SELECTED_SPLIT_TIME:
175  mp3splt_set_int_option(the_state, SPLT_OPT_SPLIT_MODE,
177  mp3splt_set_float_option(the_state, SPLT_OPT_SPLIT_TIME,
178  gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner_time)));
179  break;
180  case SELECTED_SPLIT_EQUAL_TIME_TRACKS:
181  mp3splt_set_int_option(the_state, SPLT_OPT_SPLIT_MODE,
183  mp3splt_set_int_option(the_state, SPLT_OPT_LENGTH_SPLIT_FILE_NUMBER,
184  gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner_equal_tracks)));
185  break;
186  case SELECTED_SPLIT_SILENCE:
187  mp3splt_set_int_option(the_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_SILENCE_MODE);
188  mp3splt_set_float_option(the_state, SPLT_OPT_PARAM_THRESHOLD,
189  gtk_spin_button_get_value(GTK_SPIN_BUTTON(all_spinner_silence_threshold)));
190  mp3splt_set_float_option(the_state, SPLT_OPT_PARAM_OFFSET,
191  gtk_spin_button_get_value(GTK_SPIN_BUTTON(all_spinner_silence_offset)));
192  mp3splt_set_int_option(the_state, SPLT_OPT_PARAM_NUMBER_TRACKS,
193  gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(all_spinner_silence_number_tracks)));
194  mp3splt_set_float_option(the_state, SPLT_OPT_PARAM_MIN_LENGTH,
195  gtk_spin_button_get_value(GTK_SPIN_BUTTON(all_spinner_silence_minimum)));
196  mp3splt_set_float_option(the_state, SPLT_OPT_PARAM_MIN_TRACK_LENGTH,
197  gtk_spin_button_get_value(GTK_SPIN_BUTTON(all_spinner_track_minimum)));
198  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(all_silence_remove_silence)))
199  {
200  mp3splt_set_int_option(the_state, SPLT_OPT_PARAM_REMOVE_SILENCE, SPLT_TRUE);
201  }
202  else
203  {
204  mp3splt_set_int_option(the_state, SPLT_OPT_PARAM_REMOVE_SILENCE, SPLT_FALSE);
205  }
206  break;
207  case SELECTED_SPLIT_TRIM_SILENCE:
208  mp3splt_set_int_option(the_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_TRIM_SILENCE_MODE);
209  mp3splt_set_float_option(the_state, SPLT_OPT_PARAM_THRESHOLD,
210  gtk_spin_button_get_value(GTK_SPIN_BUTTON(all_spinner_trim_silence_threshold)));
211  break;
212  case SELECTED_SPLIT_ERROR:
213  mp3splt_set_int_option(the_state, SPLT_OPT_SPLIT_MODE,
215  break;
216  default:
217  break;
218  }
219 
220  gint selected_tags_value = rh_get_active_value(tags_radio);
221  if (selected_tags_value == NO_TAGS)
222  {
223  mp3splt_set_int_option(the_state, SPLT_OPT_TAGS, SPLT_NO_TAGS);
224  }
225  else if (selected_tags_value == DEFAULT_TAGS)
226  {
227  mp3splt_set_int_option(the_state, SPLT_OPT_TAGS, SPLT_CURRENT_TAGS);
228  }
229  else if (selected_tags_value == ORIGINAL_FILE_TAGS)
230  {
231  mp3splt_set_int_option(the_state, SPLT_OPT_TAGS, SPLT_TAGS_ORIGINAL_FILE);
232  }
233  else if (selected_tags_value == TAGS_FROM_FILENAME)
234  {
235  put_tags_from_filename_regex_options();
236  }
237 
238  gint tags_radio_choice = get_checked_tags_version_radio_box();
239  if (tags_radio_choice == 0)
240  {
241  mp3splt_set_int_option(the_state, SPLT_OPT_FORCE_TAGS_VERSION, 0);
242  }
243  else if (tags_radio_choice == 1)
244  {
245  mp3splt_set_int_option(the_state, SPLT_OPT_FORCE_TAGS_VERSION, 1);
246  }
247  else if (tags_radio_choice == 2)
248  {
249  mp3splt_set_int_option(the_state, SPLT_OPT_FORCE_TAGS_VERSION, 2);
250  }
251  else if (tags_radio_choice == 3)
252  {
253  mp3splt_set_int_option(the_state, SPLT_OPT_FORCE_TAGS_VERSION, 12);
254  }
255 
256  mp3splt_set_int_option(the_state, SPLT_OPT_DEBUG_MODE, debug_is_active);
257 
258  mp3splt_set_int_option(the_state, SPLT_OPT_CREATE_DIRS_FROM_FILENAMES,
259  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(create_dirs_from_output_files)));
260 }
261 
262 void put_tags_from_filename_regex_options()
263 {
264  mp3splt_set_int_option(the_state, SPLT_OPT_TAGS, SPLT_TAGS_FROM_FILENAME_REGEX);
265 
266  gint underscores = gtk_toggle_button_get_active(
267  GTK_TOGGLE_BUTTON(replace_underscore_by_space_check_box));
268  mp3splt_set_int_option(the_state, SPLT_OPT_REPLACE_UNDERSCORES_TAG_FORMAT, underscores);
269 
270  mp3splt_set_int_option(the_state, SPLT_OPT_ARTIST_TAG_FORMAT,
271  ch_get_active_value(artist_text_properties_combo));
272 
273  mp3splt_set_int_option(the_state, SPLT_OPT_ALBUM_TAG_FORMAT,
274  ch_get_active_value(album_text_properties_combo));
275 
276  mp3splt_set_int_option(the_state, SPLT_OPT_TITLE_TAG_FORMAT,
277  ch_get_active_value(title_text_properties_combo));
278 
279  mp3splt_set_int_option(the_state, SPLT_OPT_COMMENT_TAG_FORMAT,
280  ch_get_active_value(comment_text_properties_combo));
281 
282  const gchar *regular_expression = gtk_entry_get_text(GTK_ENTRY(regex_entry));
283  mp3splt_set_input_filename_regex(the_state, regular_expression);
284 
285  const gchar *default_comment = gtk_entry_get_text(GTK_ENTRY(comment_tag_entry));
286  if (strlen(default_comment) == 0)
287  {
288  default_comment = NULL;
289  }
290  mp3splt_set_default_comment_tag(the_state, default_comment);
291 
292  mp3splt_set_default_genre_tag(the_state, ch_get_active_str_value(genre_combo));
293 }
294