mp3splt-gtk
options_manager.c
Go to the documentation of this file.
00001 /**********************************************************
00002  *
00003  * mp3splt-gtk -- utility based on mp3splt,
00004  *                for mp3/ogg splitting without decoding
00005  *
00006  * Copyright: (C) 2005-2011 Alexandru Munteanu
00007  * Contact: io_fx@yahoo.fr
00008  *
00009  * http://mp3splt.sourceforge.net/
00010  *
00011  *********************************************************/
00012 
00013 /**********************************************************
00014  *
00015  * This program is free software; you can redistribute it and/or
00016  * modify it under the terms of the GNU General Public License
00017  * as published by the Free Software Foundation; either version 2
00018  * of the License, or (at your option) any later version.
00019  *
00020  * This program is distributed in the hope that it will be useful,
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  * GNU General Public License for more details.
00024  *
00025  * You should have received a copy of the GNU General Public License
00026  * along with this program; if not, write to the Free Software
00027  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
00028  * USA.
00029  *
00030  *********************************************************/
00031 
00032 /*!********************************************************
00033  * \file
00034  *  Get the current state of all GUI buttons
00035  *
00036  * The code contained in this file reads out the current 
00037  * state of all GUI buttons and saves it into the structure
00038  * the_state.
00039  ********************************************************/
00040 
00041 #include <string.h>
00042 
00043 #include <gtk/gtk.h>
00044 #include <glib/gi18n.h>
00045 
00046 #include <libmp3splt/mp3splt.h>
00047 
00048 #include "util.h"
00049 #include "player_tab.h"
00050 #include "freedb_tab.h"
00051 #include "main_win.h"
00052 #include "preferences_tab.h"
00053 #include "special_split.h"
00054 #include "player_tab.h"
00055 #include "combo_helper.h"
00056 #include "options_manager.h"
00057 #include "radio_helper.h"
00058 
00059 extern gint debug_is_active;
00060 
00061 extern splt_state *the_state;
00062 
00063 extern GtkWidget *output_entry;
00064 extern gchar *filename_to_split;
00065 extern gint selected_split_mode;
00066 
00067 extern GtkWidget *frame_mode;
00068 extern GtkWidget *adjust_mode;
00069 extern GtkWidget *spinner_adjust_gap;
00070 extern GtkWidget *spinner_adjust_offset;
00071 extern GtkWidget *spinner_adjust_threshold;
00072 extern GtkWidget *spinner_time;
00073 extern GtkWidget *spinner_equal_tracks;
00074 extern GtkWidget *create_dirs_from_output_files;
00075 
00076 extern GtkWidget *all_spinner_silence_number_tracks;
00077 extern GtkWidget *all_spinner_silence_minimum;
00078 extern GtkWidget *all_spinner_track_minimum;
00079 extern GtkWidget *all_spinner_silence_offset;
00080 extern GtkWidget *all_spinner_silence_threshold;
00081 extern GtkWidget *all_spinner_trim_silence_threshold;
00082 extern GtkWidget *all_silence_remove_silence;
00083 
00084 extern GList *text_options_list;
00085 extern GtkWidget *replace_underscore_by_space_check_box;
00086 extern GtkComboBox *artist_text_properties_combo;
00087 extern GtkComboBox *album_text_properties_combo;
00088 extern GtkComboBox *title_text_properties_combo;
00089 extern GtkComboBox *comment_text_properties_combo;
00090 extern GtkComboBox *genre_combo;
00091 extern GtkWidget *comment_tag_entry;
00092 extern GtkWidget *regex_entry;
00093 
00094 extern GtkWidget *tags_radio;
00095 
00103 void update_output_options()
00104 {
00105   filename_to_split = inputfilename_get();
00106   mp3splt_set_filename_to_split(the_state, filename_to_split);
00107 
00108   if (get_checked_output_radio_box() == 0)
00109   {
00110     mp3splt_set_int_option(the_state, SPLT_OPT_OUTPUT_FILENAMES,
00111         SPLT_OUTPUT_FORMAT);
00112 
00113     const char *data = gtk_entry_get_text(GTK_ENTRY(output_entry));
00114     gint error = SPLT_OUTPUT_FORMAT_OK;
00115     mp3splt_set_oformat(the_state, data, &error);
00116     print_status_bar_confirmation(error);
00117   }
00118   else
00119   {
00120     mp3splt_set_int_option(the_state, SPLT_OPT_OUTPUT_FILENAMES,
00121         SPLT_OUTPUT_DEFAULT);
00122   }
00123 
00124   mp3splt_set_int_option(the_state, SPLT_OPT_DEBUG_MODE, debug_is_active);
00125 }
00126 
00134 void put_options_from_preferences()
00135 {
00136   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(frame_mode)))
00137   {
00138     mp3splt_set_int_option(the_state, SPLT_OPT_FRAME_MODE, SPLT_TRUE);
00139   }
00140   else
00141   {
00142     mp3splt_set_int_option(the_state, SPLT_OPT_FRAME_MODE, SPLT_FALSE);
00143   }
00144 
00145   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(adjust_mode)))
00146   {
00147     mp3splt_set_int_option(the_state, SPLT_OPT_AUTO_ADJUST, SPLT_TRUE);
00148     mp3splt_set_float_option(the_state, SPLT_OPT_PARAM_OFFSET,
00149         gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinner_adjust_offset)));
00150     mp3splt_set_int_option(the_state, SPLT_OPT_PARAM_GAP,
00151         gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner_adjust_gap)));
00152     mp3splt_set_float_option(the_state, SPLT_OPT_PARAM_THRESHOLD,
00153         gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinner_adjust_threshold)));
00154   }
00155   else
00156   {
00157     mp3splt_set_int_option(the_state, SPLT_OPT_AUTO_ADJUST, SPLT_FALSE);
00158   }
00159 
00160   mp3splt_set_int_option(the_state, SPLT_OPT_INPUT_NOT_SEEKABLE, SPLT_FALSE);
00161 
00162   mp3splt_set_int_option(the_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_NORMAL_MODE);
00163 
00164   switch (selected_split_mode)
00165   {
00166     case SELECTED_SPLIT_NORMAL:
00167       mp3splt_set_int_option(the_state, SPLT_OPT_SPLIT_MODE,
00168           SPLT_OPTION_NORMAL_MODE);
00169       break;
00170     case SELECTED_SPLIT_WRAP:
00171       mp3splt_set_int_option(the_state, SPLT_OPT_SPLIT_MODE,
00172           SPLT_OPTION_WRAP_MODE);
00173       break;
00174     case SELECTED_SPLIT_TIME:
00175       mp3splt_set_int_option(the_state, SPLT_OPT_SPLIT_MODE,
00176           SPLT_OPTION_TIME_MODE);
00177       mp3splt_set_float_option(the_state, SPLT_OPT_SPLIT_TIME,
00178           gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner_time)));
00179       break;
00180     case SELECTED_SPLIT_EQUAL_TIME_TRACKS:
00181       mp3splt_set_int_option(the_state, SPLT_OPT_SPLIT_MODE,
00182           SPLT_OPTION_LENGTH_MODE);
00183       mp3splt_set_int_option(the_state, SPLT_OPT_LENGTH_SPLIT_FILE_NUMBER,
00184           gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner_equal_tracks)));
00185       break;
00186     case SELECTED_SPLIT_SILENCE:
00187       mp3splt_set_int_option(the_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_SILENCE_MODE);
00188       mp3splt_set_float_option(the_state, SPLT_OPT_PARAM_THRESHOLD,
00189           gtk_spin_button_get_value(GTK_SPIN_BUTTON(all_spinner_silence_threshold)));
00190       mp3splt_set_float_option(the_state, SPLT_OPT_PARAM_OFFSET,
00191           gtk_spin_button_get_value(GTK_SPIN_BUTTON(all_spinner_silence_offset)));
00192       mp3splt_set_int_option(the_state, SPLT_OPT_PARAM_NUMBER_TRACKS,
00193           gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(all_spinner_silence_number_tracks)));
00194       mp3splt_set_float_option(the_state, SPLT_OPT_PARAM_MIN_LENGTH,
00195           gtk_spin_button_get_value(GTK_SPIN_BUTTON(all_spinner_silence_minimum)));
00196       mp3splt_set_float_option(the_state, SPLT_OPT_PARAM_MIN_TRACK_LENGTH,
00197           gtk_spin_button_get_value(GTK_SPIN_BUTTON(all_spinner_track_minimum)));
00198       if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(all_silence_remove_silence)))
00199       {
00200         mp3splt_set_int_option(the_state, SPLT_OPT_PARAM_REMOVE_SILENCE, SPLT_TRUE);
00201       }
00202       else
00203       {
00204         mp3splt_set_int_option(the_state, SPLT_OPT_PARAM_REMOVE_SILENCE, SPLT_FALSE);
00205       }
00206       break;
00207     case SELECTED_SPLIT_TRIM_SILENCE:
00208       mp3splt_set_int_option(the_state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_TRIM_SILENCE_MODE);
00209       mp3splt_set_float_option(the_state, SPLT_OPT_PARAM_THRESHOLD,
00210           gtk_spin_button_get_value(GTK_SPIN_BUTTON(all_spinner_trim_silence_threshold)));
00211       break;
00212     case SELECTED_SPLIT_ERROR:
00213       mp3splt_set_int_option(the_state, SPLT_OPT_SPLIT_MODE,
00214           SPLT_OPTION_ERROR_MODE);
00215       break;
00216     default:
00217       break;
00218   }
00219 
00220   gint selected_tags_value = rh_get_active_value(tags_radio);
00221   if (selected_tags_value == NO_TAGS)
00222   {
00223     mp3splt_set_int_option(the_state, SPLT_OPT_TAGS, SPLT_NO_TAGS);
00224   }
00225   else if (selected_tags_value == DEFAULT_TAGS)
00226   {
00227     mp3splt_set_int_option(the_state, SPLT_OPT_TAGS, SPLT_CURRENT_TAGS);
00228   }
00229   else if (selected_tags_value == ORIGINAL_FILE_TAGS)
00230   {
00231     mp3splt_set_int_option(the_state, SPLT_OPT_TAGS, SPLT_TAGS_ORIGINAL_FILE);
00232   }
00233   else if (selected_tags_value == TAGS_FROM_FILENAME)
00234   {
00235     put_tags_from_filename_regex_options();
00236   }
00237 
00238   gint tags_radio_choice = get_checked_tags_version_radio_box();
00239   if (tags_radio_choice == 0)
00240   {
00241     mp3splt_set_int_option(the_state, SPLT_OPT_FORCE_TAGS_VERSION, 0);
00242   }
00243   else if (tags_radio_choice == 1)
00244   {
00245     mp3splt_set_int_option(the_state, SPLT_OPT_FORCE_TAGS_VERSION, 1);
00246   }
00247   else if (tags_radio_choice == 2)
00248   {
00249     mp3splt_set_int_option(the_state, SPLT_OPT_FORCE_TAGS_VERSION, 2);
00250   }
00251   else if (tags_radio_choice == 3)
00252   {
00253     mp3splt_set_int_option(the_state, SPLT_OPT_FORCE_TAGS_VERSION, 12);
00254   }
00255 
00256   mp3splt_set_int_option(the_state, SPLT_OPT_DEBUG_MODE, debug_is_active);
00257 
00258   mp3splt_set_int_option(the_state, SPLT_OPT_CREATE_DIRS_FROM_FILENAMES, 
00259       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(create_dirs_from_output_files)));
00260 }
00261 
00262 void put_tags_from_filename_regex_options()
00263 {
00264   mp3splt_set_int_option(the_state, SPLT_OPT_TAGS, SPLT_TAGS_FROM_FILENAME_REGEX);
00265 
00266   gint underscores = gtk_toggle_button_get_active(
00267       GTK_TOGGLE_BUTTON(replace_underscore_by_space_check_box));
00268   mp3splt_set_int_option(the_state, SPLT_OPT_REPLACE_UNDERSCORES_TAG_FORMAT, underscores);
00269 
00270   mp3splt_set_int_option(the_state, SPLT_OPT_ARTIST_TAG_FORMAT, 
00271       ch_get_active_value(artist_text_properties_combo));
00272 
00273   mp3splt_set_int_option(the_state, SPLT_OPT_ALBUM_TAG_FORMAT, 
00274       ch_get_active_value(album_text_properties_combo));
00275 
00276   mp3splt_set_int_option(the_state, SPLT_OPT_TITLE_TAG_FORMAT,
00277       ch_get_active_value(title_text_properties_combo));
00278 
00279   mp3splt_set_int_option(the_state, SPLT_OPT_COMMENT_TAG_FORMAT, 
00280       ch_get_active_value(comment_text_properties_combo));
00281 
00282   const gchar *regular_expression = gtk_entry_get_text(GTK_ENTRY(regex_entry));
00283   mp3splt_set_input_filename_regex(the_state, regular_expression);
00284 
00285   const gchar *default_comment = gtk_entry_get_text(GTK_ENTRY(comment_tag_entry));
00286   if (strlen(default_comment) == 0)
00287   {
00288     default_comment = NULL;
00289   }
00290   mp3splt_set_default_comment_tag(the_state, default_comment);
00291 
00292   mp3splt_set_default_genre_tag(the_state, ch_get_active_str_value(genre_combo));
00293 }
00294