00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00039 #include <string.h>
00040
00041 #include "splt.h"
00042
00043 static void splt_t_set_default_state_values(splt_state *state, int *error)
00044 {
00045 state->split.tags = NULL;
00046 splt_tu_reset_tags(splt_tu_get_tags_like_x(state));
00047 state->split.points = NULL;
00048 state->fname_to_split = NULL;
00049 state->path_of_split = NULL;
00050 state->m3u_filename = NULL;
00051 state->input_fname_regex = NULL;
00052 state->default_comment_tag = NULL;
00053 state->default_genre_tag = NULL;
00054 state->silence_log_fname = NULL;
00055
00056 state->split.real_tagsnumber = 0;
00057 state->split.real_splitnumber = 0;
00058 state->split.splitnumber = 0;
00059 state->split.current_split_file_number = 1;
00060 state->split.get_silence_level = NULL;
00061 state->split.put_message = NULL;
00062 state->split.file_split = NULL;
00063 state->split.p_bar->progress_text_max_char = 40;
00064 snprintf(state->split.p_bar->filename_shorted,512, "%s","");
00065 state->split.p_bar->percent_progress = 0;
00066 state->split.p_bar->current_split = 0;
00067 state->split.p_bar->max_splits = 0;
00068 state->split.p_bar->progress_type = SPLT_PROGRESS_PREPARE;
00069 state->split.p_bar->silence_found_tracks = 0;
00070 state->split.p_bar->silence_db_level = 0;
00071 state->split.p_bar->user_data = 0;
00072 state->split.p_bar->progress = NULL;
00073 state->cancel_split = SPLT_FALSE;
00074
00075 splt_original_tags *original_tags = &state->original_tags;
00076 splt_tu_reset_tags(&original_tags->tags);
00077 original_tags->all_original_tags = NULL;
00078
00079 splt_w_set_wrap_default_values(state);
00080 splt_se_set_sync_errors_default_values(state);
00081 if (splt_of_set_default_values(state) < 0) { return; }
00082 splt_e_set_errors_default_values(state);
00083 splt_fu_set_default_values(state);
00084 splt_o_set_options_default_values(state);
00085 splt_o_set_ioptions_default_values(state);
00086 splt_p_set_default_values(state);
00087 }
00088
00089 splt_state *splt_t_new_state(splt_state *state, int *error)
00090 {
00091 if ((state =malloc(sizeof(splt_state))) ==NULL)
00092 {
00093 *error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00094 return NULL;
00095 }
00096
00097 memset(state, 0x0, sizeof(splt_state));
00098 if ((state->wrap = malloc(sizeof(splt_wrap))) == NULL)
00099 {
00100 *error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00101 free(state);
00102 return NULL;
00103 }
00104 memset(state->wrap, 0x0, sizeof(state->wrap));
00105
00106 if ((state->serrors = malloc(sizeof(splt_syncerrors))) == NULL)
00107 {
00108 free(state->wrap);
00109 free(state);
00110 *error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00111 return NULL;
00112 }
00113 memset(state->serrors, 0x0, sizeof(state->serrors));
00114
00115 if ((state->split.p_bar = malloc(sizeof(splt_progress))) == NULL)
00116 {
00117 free(state->wrap);
00118 free(state->serrors);
00119 free(state);
00120 *error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00121 return NULL;
00122 }
00123
00124 if ((state->plug = malloc(sizeof(splt_plugins))) == NULL)
00125 {
00126 free(state->wrap);
00127 free(state->serrors);
00128 free(state->split.p_bar);
00129 free(state);
00130 *error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00131 return NULL;
00132 }
00133
00134 state->current_plugin = -1;
00135
00136 splt_t_set_default_state_values(state, error);
00137
00138 return state;
00139 }
00140
00141 static void splt_t_free_state_struct(splt_state *state)
00142 {
00143 if (state)
00144 {
00145 if (state->fname_to_split)
00146 {
00147 free(state->fname_to_split);
00148 state->fname_to_split = NULL;
00149 }
00150 if (state->path_of_split)
00151 {
00152 free(state->path_of_split);
00153 state->path_of_split = NULL;
00154 }
00155 if (state->m3u_filename)
00156 {
00157 free(state->m3u_filename);
00158 state->m3u_filename = NULL;
00159 }
00160 if (state->input_fname_regex)
00161 {
00162 free(state->input_fname_regex);
00163 state->input_fname_regex = NULL;
00164 }
00165 if (state->default_comment_tag)
00166 {
00167 free(state->default_comment_tag);
00168 state->default_comment_tag = NULL;
00169 }
00170 if (state->default_genre_tag)
00171 {
00172 free(state->default_genre_tag);
00173 state->default_genre_tag = NULL;
00174 }
00175 if (state->silence_log_fname)
00176 {
00177 free(state->silence_log_fname);
00178 state->silence_log_fname = NULL;
00179 }
00180 if (state->wrap)
00181 {
00182 free(state->wrap);
00183 state->wrap = NULL;
00184 }
00185 if (state->serrors)
00186 {
00187 free(state->serrors);
00188 state->serrors = NULL;
00189 }
00190 if (state->plug)
00191 {
00192 free(state->plug);
00193 state->plug = NULL;
00194 }
00195
00196 free(state);
00197 state = NULL;
00198 }
00199 }
00200
00201 void splt_t_free_state(splt_state *state)
00202 {
00203 if (state)
00204 {
00205 splt_tu_free_original_tags(state);
00206 splt_of_free_oformat(state);
00207 splt_w_wrap_free(state);
00208 splt_se_serrors_free(state);
00209 splt_fu_freedb_free_search(state);
00210 splt_t_free_splitpoints_tags(state);
00211 splt_o_iopts_free(state);
00212 splt_p_free_plugins(state);
00213 if (state->split.p_bar)
00214 {
00215 free(state->split.p_bar);
00216 state->split.p_bar = NULL;
00217 }
00218 splt_e_free_errors(state);
00219 splt_t_free_state_struct(state);
00220 }
00221 }
00222
00223 void splt_t_set_total_time(splt_state *state, long value)
00224 {
00225 splt_d_print_debug(state,"Setting total time to _%ld_\n", value);
00226
00227 if (value >= 0)
00228 {
00229 state->split.total_time = value;
00230 }
00231 else
00232 {
00233 splt_e_error(SPLT_IERROR_INT,__func__, value, NULL);
00234 }
00235 }
00236
00237 long splt_t_get_total_time(splt_state *state)
00238 {
00239 return state->split.total_time;
00240 }
00241
00242 double splt_t_get_total_time_as_double_secs(splt_state *state)
00243 {
00244 long total_time = splt_t_get_total_time(state);
00245
00246 double total = total_time / 100;
00247 total += ((total_time % 100) / 100.);
00248
00249 return total;
00250 }
00251
00252 void splt_t_set_new_filename_path(splt_state *state,
00253 const char *new_filename_path, int *error)
00254 {
00255 int err = SPLT_OK;
00256
00257 splt_internal *iopts = &state->iopts;
00258 err = splt_su_copy(new_filename_path, &iopts->new_filename_path);
00259 if (err < 0) { *error = err; }
00260 }
00261
00262 char *splt_t_get_new_filename_path(splt_state *state)
00263 {
00264 return state->iopts.new_filename_path;
00265 }
00266
00267 int splt_t_set_path_of_split(splt_state *state, const char *path_of_split)
00268 {
00269 splt_d_print_debug(state,"Setting path of split to _%s_\n", path_of_split);
00270 int err = splt_su_copy(path_of_split, &state->path_of_split);
00271
00272 if (state->path_of_split == NULL)
00273 {
00274 return err;
00275 }
00276
00277 #ifdef __WIN32__
00278 if (state->path_of_split[strlen(state->path_of_split)-1] == SPLT_DIRCHAR)
00279 {
00280 if (! splt_w32_str_is_drive_root_directory(state->path_of_split))
00281 {
00282 splt_su_str_cut_last_char(state->path_of_split);
00283 }
00284 }
00285 #endif
00286
00287 return err;
00288 }
00289
00290 char *splt_t_get_path_of_split(splt_state *state)
00291 {
00292 return state->path_of_split;
00293 }
00294
00295 int splt_t_set_m3u_filename(splt_state *state, const char *filename)
00296 {
00297 splt_d_print_debug(state,"Setting m3u filename to _%s_\n", filename);
00298 return splt_su_copy(filename, &state->m3u_filename);
00299 }
00300
00301 char *splt_t_get_m3u_filename(splt_state *state)
00302 {
00303 return state->m3u_filename;
00304 }
00305
00306 int splt_t_set_input_filename_regex(splt_state *state, const char *regex)
00307 {
00308 splt_d_print_debug(state, "Setting input filename regex to _%s_\n", regex);
00309 return splt_su_copy(regex, &state->input_fname_regex);
00310 }
00311
00312 char *splt_t_get_input_filename_regex(splt_state *state)
00313 {
00314 return state->input_fname_regex;
00315 }
00316
00317 int splt_t_set_default_comment_tag(splt_state *state, const char *default_comment)
00318 {
00319 splt_d_print_debug(state,"Setting default comment tag to _%s_\n", default_comment);
00320 return splt_su_copy(default_comment, &state->default_comment_tag);
00321 }
00322
00323 int splt_t_set_default_genre_tag(splt_state *state, const char *default_genre)
00324 {
00325 splt_d_print_debug(state,"Setting default genre tag to _%s_\n", default_genre);
00326 return splt_su_copy(default_genre, &state->default_genre_tag);
00327 }
00328
00329 char *splt_t_get_default_comment_tag(splt_state *state)
00330 {
00331 return state->default_comment_tag;
00332 }
00333
00334 char *splt_t_get_default_genre_tag(splt_state *state)
00335 {
00336 return state->default_genre_tag;
00337 }
00338
00339 char *splt_t_get_m3u_file_with_path(splt_state *state, int *error)
00340 {
00341 char *m3u_file = splt_t_get_m3u_filename(state);
00342 return splt_su_get_file_with_output_path(state, m3u_file, error);
00343 }
00344
00345 int splt_t_set_silence_log_fname(splt_state *state, const char *filename)
00346 {
00347 splt_d_print_debug(state,"Setting silence log fname to _%s_\n", filename);
00348 return splt_su_copy(filename, &state->silence_log_fname);
00349 }
00350
00351 char *splt_t_get_silence_log_fname(splt_state *state)
00352 {
00353 return state->silence_log_fname;
00354 }
00355
00357 int splt_t_set_filename_to_split(splt_state *state, const char *filename)
00358 {
00359 splt_d_print_debug(state,"Setting filename to split to _%s_\n", filename);
00360 return splt_su_copy(filename, &state->fname_to_split);
00361 }
00362
00364 char * splt_t_get_filename_to_split(splt_state *state)
00365 {
00366 return state->fname_to_split;
00367 }
00368
00369 static void splt_t_set_current_split_file_number(splt_state *state, int index)
00370 {
00371 state->split.current_split_file_number = index;
00372 }
00373
00374 static void splt_t_set_current_split_file_number_next(splt_state *state)
00375 {
00376 splt_t_set_current_split_file_number(state, state->split.current_split_file_number+1);
00377 }
00378
00379 void splt_t_set_current_split(splt_state *state, int index)
00380 {
00381 if (index >= 0)
00382 {
00383 int err = SPLT_OK;
00384 if (index == 0)
00385 {
00386 if (splt_sp_splitpoint_exists(state, index) &&
00387 splt_sp_get_splitpoint_type(state, index, &err) == SPLT_SKIPPOINT)
00388 {
00389 splt_t_set_current_split_file_number(state, 0);
00390 }
00391 else
00392 {
00393 splt_t_set_current_split_file_number(state, 1);
00394 }
00395 }
00396 else
00397 {
00398 if (splt_sp_splitpoint_exists(state, index))
00399 {
00400 if (splt_sp_get_splitpoint_type(state, index, &err) != SPLT_SKIPPOINT)
00401 {
00402 splt_t_set_current_split_file_number_next(state);
00403 }
00404 }
00405 else
00406 {
00407 splt_t_set_current_split_file_number_next(state);
00408 }
00409 }
00410
00411 state->split.current_split = index;
00412 }
00413 else
00414 {
00415 splt_e_error(SPLT_IERROR_INT, __func__,index, NULL);
00416 }
00417 }
00418
00419 void splt_t_current_split_next(splt_state *state)
00420 {
00421 splt_t_set_current_split(state, splt_t_get_current_split(state) + 1);
00422 }
00423
00424 int splt_t_get_current_split(splt_state *state)
00425 {
00426 return state->split.current_split;
00427 }
00428
00429 int splt_t_get_current_split_file_number(splt_state *state)
00430 {
00431 return state->split.current_split_file_number;
00432 }
00433
00434 void splt_t_set_splitnumber(splt_state *state, int number)
00435 {
00436 if (number >= 0)
00437 {
00438 state->split.splitnumber = number;
00439 }
00440 else
00441 {
00442 splt_e_error(SPLT_IERROR_INT,__func__, number, NULL);
00443 }
00444 }
00445
00446 int splt_t_get_splitnumber(splt_state *state)
00447 {
00448 return state->split.splitnumber;
00449 }
00450
00451 void splt_t_free_splitpoints_tags(splt_state *state)
00452 {
00453 splt_sp_free_splitpoints(state);
00454 splt_tu_free_tags(state);
00455 }
00456
00457 void splt_t_clean_one_split_data(splt_state *state, int num)
00458 {
00459 if (splt_tu_tags_exists(state,num))
00460 {
00461 splt_tu_set_tags_field(state,num, SPLT_TAGS_YEAR, NULL);
00462 splt_tu_set_tags_field(state,num, SPLT_TAGS_ARTIST, NULL);
00463 splt_tu_set_tags_field(state,num, SPLT_TAGS_ALBUM, NULL);
00464 splt_tu_set_tags_field(state,num, SPLT_TAGS_TITLE, NULL);
00465 splt_tu_set_tags_field(state,num, SPLT_TAGS_COMMENT, NULL);
00466 splt_tu_set_tags_field(state,num, SPLT_TAGS_PERFORMER, NULL);
00467 }
00468
00469 if (splt_sp_splitpoint_exists(state, num))
00470 {
00471 splt_sp_set_splitpoint_name(state, num, NULL);
00472 }
00473 }
00474
00475 void splt_t_clean_split_data(splt_state *state,int tracks)
00476 {
00477 splt_t_set_current_split(state,0);
00478 do {
00479 splt_t_clean_one_split_data(state,state->split.current_split);
00480 splt_t_current_split_next(state);
00481 } while (splt_t_get_current_split(state) < tracks);
00482 }
00483
00484 int splt_t_split_is_canceled(splt_state *state)
00485 {
00486 return state->cancel_split;
00487 }
00488
00489 void splt_t_set_stop_split(splt_state *state, int bool_value)
00490 {
00491 state->cancel_split = bool_value;
00492 }
00493