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
00067 #include <sys/stat.h>
00068 #include <string.h>
00069
00070 #include <ltdl.h>
00071
00072 #include "splt.h"
00073
00074 int global_debug = SPLT_FALSE;
00075
00098 splt_state *mp3splt_new_state(int *error)
00099 {
00100 splt_state *state = NULL;
00101
00102 int erro = SPLT_OK;
00103 int *err = &erro;
00104 if (error != NULL) { err = error; }
00105
00106 if (lt_dlinit() != 0)
00107 {
00108 *err = SPLT_ERROR_CANNOT_INIT_LIBLTDL;
00109 }
00110 else
00111 {
00112
00113 #ifdef ENABLE_NLS
00114 # ifndef __WIN32__
00115 bindtextdomain(MP3SPLT_LIB_GETTEXT_DOMAIN, LOCALEDIR);
00116 # endif
00117 bind_textdomain_codeset(MP3SPLT_LIB_GETTEXT_DOMAIN, "UTF-8");
00118 #endif
00119
00120 state = splt_t_new_state(state, err);
00121 }
00122
00123 return state;
00124 }
00125
00130 int mp3splt_find_plugins(splt_state *state)
00131 {
00132 return splt_p_find_get_plugins_data(state);
00133 }
00134
00144 void mp3splt_free_state(splt_state *state, int *error)
00145 {
00146 if (!state)
00147 {
00148 return;
00149 }
00150
00151 int erro = SPLT_OK;
00152 int *err = &erro;
00153 if (error != NULL) { err = error; }
00154
00155 if (state != NULL)
00156 {
00157 if (!splt_o_library_locked(state))
00158 {
00159 splt_o_lock_library(state);
00160
00161 splt_t_free_state(state);
00162 }
00163 else
00164 {
00165 *err = SPLT_ERROR_LIBRARY_LOCKED;
00166 }
00167 }
00168 else
00169 {
00170 *err = SPLT_ERROR_STATE_NULL;
00171 }
00172 }
00173
00175 int mp3splt_set_path_of_split(splt_state *state, const char *path)
00176 {
00177 int error = SPLT_OK;
00178
00179 if (state != NULL)
00180 {
00181 if (!splt_o_library_locked(state))
00182 {
00183 splt_o_lock_library(state);
00184
00185 error = splt_t_set_path_of_split(state, path);
00186
00187 splt_o_unlock_library(state);
00188 }
00189 else
00190 {
00191 error = SPLT_ERROR_LIBRARY_LOCKED;
00192 }
00193 }
00194 else
00195 {
00196 error = SPLT_ERROR_STATE_NULL;
00197 }
00198
00199 return error;
00200 }
00201
00207 int mp3splt_set_m3u_filename(splt_state *state, const char *filename)
00208 {
00209 int error = SPLT_OK;
00210
00211 if (state != NULL)
00212 {
00213 if (!splt_o_library_locked(state))
00214 {
00215 splt_o_lock_library(state);
00216
00217 error = splt_t_set_m3u_filename(state, filename);
00218
00219 splt_o_unlock_library(state);
00220 }
00221 else
00222 {
00223 error = SPLT_ERROR_LIBRARY_LOCKED;
00224 }
00225 }
00226 else
00227 {
00228 error = SPLT_ERROR_STATE_NULL;
00229 }
00230
00231 return error;
00232 }
00233
00235 int mp3splt_set_silence_log_filename(splt_state *state, const char *filename)
00236 {
00237 int error = SPLT_OK;
00238
00239 if (state != NULL)
00240 {
00241 if (!splt_o_library_locked(state))
00242 {
00243 splt_o_lock_library(state);
00244
00245 error = splt_t_set_silence_log_fname(state, filename);
00246
00247 splt_o_unlock_library(state);
00248 }
00249 else
00250 {
00251 error = SPLT_ERROR_LIBRARY_LOCKED;
00252 }
00253 }
00254 else
00255 {
00256 error = SPLT_ERROR_STATE_NULL;
00257 }
00258
00259 return error;
00260 }
00261
00266 char *mp3splt_get_filename_to_split(splt_state *state)
00267 {
00268 return splt_t_get_filename_to_split(state);
00269 }
00270
00276 int mp3splt_set_filename_to_split(splt_state *state, const char *filename)
00277 {
00278 int error = SPLT_OK;
00279
00280 if (state != NULL)
00281 {
00282 if (!splt_o_library_locked(state))
00283 {
00284 splt_o_lock_library(state);
00285
00286 error = splt_t_set_filename_to_split(state, filename);
00287
00288 splt_o_unlock_library(state);
00289 }
00290 else
00291 {
00292 error = SPLT_ERROR_LIBRARY_LOCKED;
00293 }
00294 }
00295 else
00296 {
00297 error = SPLT_ERROR_STATE_NULL;
00298 }
00299
00300 return error;
00301 }
00302
00303 int mp3splt_set_input_filename_regex(splt_state *state, const char *regex)
00304 {
00305 int error = SPLT_OK;
00306
00307 if (state != NULL)
00308 {
00309 if (!splt_o_library_locked(state))
00310 {
00311 splt_o_lock_library(state);
00312
00313 error = splt_t_set_input_filename_regex(state, regex);
00314
00315 splt_o_unlock_library(state);
00316 }
00317 else
00318 {
00319 error = SPLT_ERROR_LIBRARY_LOCKED;
00320 }
00321 }
00322 else
00323 {
00324 error = SPLT_ERROR_STATE_NULL;
00325 }
00326
00327 return error;
00328 }
00329
00330 int mp3splt_set_default_comment_tag(splt_state *state, const char *default_comment)
00331 {
00332 int error = SPLT_OK;
00333
00334 if (state != NULL)
00335 {
00336 if (!splt_o_library_locked(state))
00337 {
00338 splt_o_lock_library(state);
00339
00340 error = splt_t_set_default_comment_tag(state, default_comment);
00341
00342 splt_o_unlock_library(state);
00343 }
00344 else
00345 {
00346 error = SPLT_ERROR_LIBRARY_LOCKED;
00347 }
00348 }
00349 else
00350 {
00351 error = SPLT_ERROR_STATE_NULL;
00352 }
00353
00354 return error;
00355 }
00356
00357 int mp3splt_set_default_genre_tag(splt_state *state, const char *default_genre_tag)
00358 {
00359 int error = SPLT_OK;
00360
00361 if (state != NULL)
00362 {
00363 if (!splt_o_library_locked(state))
00364 {
00365 splt_o_lock_library(state);
00366
00367 error = splt_t_set_default_genre_tag(state, default_genre_tag);
00368
00369 splt_o_unlock_library(state);
00370 }
00371 else
00372 {
00373 error = SPLT_ERROR_LIBRARY_LOCKED;
00374 }
00375 }
00376 else
00377 {
00378 error = SPLT_ERROR_STATE_NULL;
00379 }
00380
00381 return error;
00382 }
00383
00384
00385
00386
00387
00394 int mp3splt_set_message_function(splt_state *state,
00395 void (*message_cb)(const char *, splt_message_type))
00396 {
00397 int error = SPLT_OK;
00398
00399 if (state != NULL)
00400 {
00401 state->split.put_message = message_cb;
00402 }
00403 else
00404 {
00405 error = SPLT_ERROR_STATE_NULL;
00406 }
00407
00408 return error;
00409 }
00410
00417 int mp3splt_set_split_filename_function(splt_state *state,
00418 void (*file_cb)(const char *,int b))
00419 {
00420 int error = SPLT_OK;
00421
00422 if (state != NULL)
00423 {
00424 state->split.file_split = file_cb;
00425 }
00426 else
00427 {
00428 error = SPLT_ERROR_STATE_NULL;
00429 }
00430
00431 return error;
00432 }
00433
00440 int mp3splt_set_progress_function(splt_state *state,
00441 void (*progress_cb)(splt_progress *p_bar))
00442 {
00443 int error = SPLT_OK;
00444
00445 if (state != NULL)
00446 {
00447 state->split.p_bar->progress = progress_cb;
00448 }
00449 else
00450 {
00451 error = SPLT_ERROR_STATE_NULL;
00452 }
00453
00454 return error;
00455 }
00456 int mp3splt_set_silence_level_function(splt_state *state,
00464 void (*get_silence_cb)(long time, float level, void *user_data),
00465 void *data)
00466 {
00467 int error = SPLT_OK;
00468
00469 if (state != NULL)
00470 {
00471 state->split.get_silence_level = get_silence_cb;
00472 state->split.silence_level_client_data = data;
00473 }
00474 else
00475 {
00476 error = SPLT_ERROR_STATE_NULL;
00477 }
00478
00479 return error;
00480 }
00481
00482
00483
00484
00494 int mp3splt_append_splitpoint(splt_state *state,
00495 long split_value, const char *name, int type)
00496 {
00497 int error = SPLT_OK;
00498
00499 if (state != NULL)
00500 {
00501 if (!splt_o_library_locked(state))
00502 {
00503 splt_o_lock_library(state);
00504
00505 error = splt_sp_append_splitpoint(state, split_value, name, type);
00506
00507 splt_o_unlock_library(state);
00508 }
00509 else
00510 {
00511 error = SPLT_ERROR_LIBRARY_LOCKED;
00512 }
00513 }
00514 else
00515 {
00516 error = SPLT_ERROR_STATE_NULL;
00517 }
00518
00519 return error;
00520 }
00521
00529 const splt_point *mp3splt_get_splitpoints(splt_state *state,
00530 int *splitpoints_number, int *error)
00531 {
00532 int erro = SPLT_OK;
00533 int *err = &erro;
00534 if (error != NULL) { err = error; }
00535
00536 if (state != NULL)
00537 {
00538 return splt_sp_get_splitpoints(state, splitpoints_number);
00539 }
00540 else
00541 {
00542 *err = SPLT_ERROR_STATE_NULL;
00543 return 0;
00544 }
00545 }
00546
00552 void mp3splt_erase_all_splitpoints(splt_state *state, int *error)
00553 {
00554 int erro = SPLT_OK;
00555 int *err = &erro;
00556 if (error != NULL) { err = error; }
00557
00558 if (state != NULL)
00559 {
00560 if (!splt_o_library_locked(state))
00561 {
00562 splt_o_lock_library(state);
00563
00564 splt_sp_free_splitpoints(state);
00565
00566 splt_o_unlock_library(state);
00567 }
00568 else
00569 {
00570 *err = SPLT_ERROR_LIBRARY_LOCKED;
00571 }
00572 }
00573 else
00574 {
00575 *err = SPLT_ERROR_STATE_NULL;
00576 }
00577 }
00578
00579
00580
00581
00583 int mp3splt_append_tags(splt_state *state,
00584 const char *title, const char *artist,
00585 const char *album, const char *performer,
00586 const char *year, const char *comment,
00587 int track, const char *genre)
00588 {
00589 int error = SPLT_OK;
00590
00591 if (state != NULL)
00592 {
00593 if (!splt_o_library_locked(state))
00594 {
00595 splt_o_lock_library(state);
00596
00597 error = splt_tu_append_tags(state, title, artist,
00598 album, performer, year, comment, track, genre, SPLT_FALSE);
00599
00600 splt_o_unlock_library(state);
00601 }
00602 else
00603 {
00604 error = SPLT_ERROR_LIBRARY_LOCKED;
00605 }
00606 }
00607 else
00608 {
00609 error = SPLT_ERROR_STATE_NULL;
00610 }
00611
00612 return error;
00613 }
00614
00616 const splt_tags *mp3splt_get_tags(splt_state *state,
00617 int *tags_number, int *error)
00618 {
00619 int erro = SPLT_OK;
00620 int *err = &erro;
00621 if (error != NULL) { err = error; }
00622
00623 if (state != NULL)
00624 {
00625 return splt_tu_get_tags(state,tags_number);
00626 }
00627 else
00628 {
00629 *err = SPLT_ERROR_STATE_NULL;
00630 return NULL;
00631 }
00632 }
00633
00635 int mp3splt_put_tags_from_string(splt_state *state, const char *tags, int *error)
00636 {
00637 int ambigous = SPLT_FALSE;
00638 int erro = SPLT_OK;
00639 int *err = &erro;
00640 if (error != NULL) { err = error; }
00641
00642 if (state != NULL)
00643 {
00644 if (!splt_o_library_locked(state))
00645 {
00646 splt_o_lock_library(state);
00647
00648 ambigous = splt_tp_put_tags_from_string(state, tags, err);
00649
00650 splt_o_unlock_library(state);
00651 }
00652 else
00653 {
00654 *err = SPLT_ERROR_LIBRARY_LOCKED;
00655 }
00656 }
00657 else
00658 {
00659 *err = SPLT_ERROR_STATE_NULL;
00660 }
00661
00662 return ambigous;
00663 }
00664
00666 void mp3splt_erase_all_tags(splt_state *state, int *error)
00667 {
00668 int erro = SPLT_OK;
00669 int *err = &erro;
00670 if (error != NULL) { err = error; }
00671
00672 if (state != NULL)
00673 {
00674 if (!splt_o_library_locked(state))
00675 {
00676 splt_o_lock_library(state);
00677
00678 splt_tu_free_tags(state);
00679
00680 splt_o_unlock_library(state);
00681 }
00682 else
00683 {
00684 *err = SPLT_ERROR_LIBRARY_LOCKED;
00685 }
00686 }
00687 else
00688 {
00689 *err = SPLT_ERROR_STATE_NULL;
00690 }
00691 }
00692
00693
00694
00695
00696 static int mp3splt_set_option(splt_state *state, int option_name, void *value)
00697 {
00698 int error = SPLT_OK;
00699
00700 if (state != NULL)
00701 {
00702 if (!splt_o_library_locked(state))
00703 {
00704 splt_o_lock_library(state);
00705
00706 splt_o_set_option(state, option_name, value);
00707
00708 splt_o_unlock_library(state);
00709 }
00710 else
00711 {
00712 error = SPLT_ERROR_LIBRARY_LOCKED;
00713 }
00714 }
00715 else
00716 {
00717 error = SPLT_ERROR_STATE_NULL;
00718 }
00719
00720 return error;
00721 }
00722
00723 int mp3splt_set_int_option(splt_state *state, int option_name, int value)
00724 {
00725 return mp3splt_set_option(state, option_name, &value);
00726 }
00727
00728 int mp3splt_set_long_option(splt_state *state, int option_name, long value)
00729 {
00730 return mp3splt_set_option(state, option_name, &value);
00731 }
00732
00733 int mp3splt_set_float_option(splt_state *state, int option_name, float value)
00734 {
00735 return mp3splt_set_option(state, option_name, &value);
00736 }
00737
00738 int mp3splt_get_int_option(splt_state *state, int option_name, int *error)
00739 {
00740 int erro = SPLT_OK;
00741 int *err = &erro;
00742 if (error != NULL) { err = error; }
00743
00744 if (state != NULL)
00745 {
00746 return splt_o_get_int_option(state, option_name);
00747 }
00748 else
00749 {
00750 *err = SPLT_ERROR_STATE_NULL;
00751 return 0;
00752 }
00753 }
00754
00755 long mp3splt_get_long_option(splt_state *state, int option_name, int *error)
00756 {
00757 int erro = SPLT_OK;
00758 int *err = &erro;
00759 if (error != NULL) { err = error; }
00760
00761 if (state != NULL)
00762 {
00763 return splt_o_get_long_option(state, option_name);
00764 }
00765 else
00766 {
00767 *err = SPLT_ERROR_STATE_NULL;
00768 return 0;
00769 }
00770 }
00771
00772 float mp3splt_get_float_option(splt_state *state, int option_name, int *error)
00773 {
00774 int erro = SPLT_OK;
00775 int *err = &erro;
00776 if (error != NULL) { err = error; }
00777
00778 if (state != NULL)
00779 {
00780 return splt_o_get_float_option(state, option_name);
00781 }
00782 else
00783 {
00784 *err = SPLT_ERROR_STATE_NULL;
00785 return 0;
00786 }
00787 }
00788
00789
00790
00791
00797 int mp3splt_split(splt_state *state)
00798 {
00799 int error = SPLT_OK;
00800
00801 if (state != NULL)
00802 {
00803 if (!splt_o_library_locked(state))
00804 {
00805 splt_o_lock_library(state);
00806
00807 splt_d_print_debug(state,"Starting to split file ...\n");
00808
00809 char *new_filename_path = NULL;
00810 char *fname_to_split = splt_t_get_filename_to_split(state);
00811
00812 splt_d_print_debug(state,"Original filename/path to split is _%s_\n", fname_to_split);
00813
00814 if (splt_io_input_is_stdin(state))
00815 {
00816 splt_o_set_int_option(state, SPLT_OPT_INPUT_NOT_SEEKABLE, SPLT_TRUE);
00817 }
00818
00819 splt_t_set_stop_split(state, SPLT_FALSE);
00820
00821 splt_o_set_default_iopts(state);
00822
00823
00824
00825 state->split.splitnumber = state->split.real_splitnumber;
00826 splt_t_set_current_split(state,0);
00827
00828 if (!splt_io_check_if_file(state, fname_to_split))
00829 {
00830 error = SPLT_ERROR_INEXISTENT_FILE;
00831 splt_o_unlock_library(state);
00832 return error;
00833 }
00834
00835 #ifndef __WIN32__
00836 char *linked_fname = splt_io_get_linked_fname(fname_to_split, NULL);
00837 if (linked_fname)
00838 {
00839 splt_c_put_info_message_to_client(state,
00840 _(" info: resolving linked filename to '%s'\n"), linked_fname);
00841
00842 splt_t_set_filename_to_split(state, linked_fname);
00843 fname_to_split = splt_t_get_filename_to_split(state);
00844
00845 free(linked_fname);
00846 linked_fname = NULL;
00847 }
00848 #endif
00849
00850
00851
00852 new_filename_path = splt_check_put_dir_of_cur_song(fname_to_split,
00853 splt_t_get_path_of_split(state), &error);
00854 if (error < 0)
00855 {
00856 splt_o_unlock_library(state);
00857 return error;
00858 }
00859
00860
00861 splt_check_set_correct_options(state);
00862
00863
00864
00865 if (! splt_check_compatible_options(state))
00866 {
00867 error = SPLT_ERROR_INCOMPATIBLE_OPTIONS;
00868 goto function_end;
00869 }
00870
00871 int split_type = splt_o_get_int_option(state, SPLT_OPT_SPLIT_MODE);
00872
00873 splt_t_set_new_filename_path(state, new_filename_path, &error);
00874 if (error < 0) { goto function_end; }
00875
00876 splt_d_print_debug(state, "new fname path = _%s_\n", new_filename_path);
00877
00878 error = splt_io_create_directories(state, new_filename_path);
00879 if (error < 0) { goto function_end; }
00880
00881 splt_check_if_fname_path_is_correct(state, new_filename_path, &error);
00882 if (error < 0) { goto function_end; }
00883
00884
00885 splt_check_file_type(state, &error);
00886 if (error < 0) { goto function_end; }
00887
00888 int tags_option = splt_o_get_int_option(state, SPLT_OPT_TAGS);
00889 if (tags_option == SPLT_TAGS_ORIGINAL_FILE)
00890 {
00891 splt_tp_put_tags_from_string(state, SPLT_ORIGINAL_TAGS_DEFAULT, &error);
00892 if (error < 0) { goto function_end; }
00893 }
00894 else if (tags_option == SPLT_TAGS_FROM_FILENAME_REGEX)
00895 {
00896 int regex_error = SPLT_OK;
00897 splt_tp_put_tags_from_filename(state, ®ex_error);
00898 if (regex_error < 0) { error = regex_error; goto function_end; }
00899 }
00900
00901 const char *plugin_name = splt_p_get_name(state,&error);
00902 if (error < 0) { goto function_end; }
00903
00904 splt_c_put_info_message_to_client(state,
00905 _(" info: file matches the plugin '%s'\n"), plugin_name);
00906
00907
00908 char *m3u_fname_with_path = splt_t_get_m3u_file_with_path(state, &error);
00909 if (error < 0) { goto function_end; }
00910 if (m3u_fname_with_path)
00911 {
00912 splt_c_put_info_message_to_client(state,
00913 _(" M3U file '%s' will be created.\n"), m3u_fname_with_path);
00914
00915 free(m3u_fname_with_path);
00916 m3u_fname_with_path = NULL;
00917 }
00918
00919
00920 splt_p_init(state, &error);
00921 if (error < 0) { goto function_end; }
00922
00923 splt_d_print_debug(state,"Parse type of split ...\n");
00924
00925 if (splt_o_get_int_option(state, SPLT_OPT_AUTO_ADJUST)
00926 && !splt_o_get_int_option(state, SPLT_OPT_QUIET_MODE))
00927 {
00928 if ((split_type != SPLT_OPTION_WRAP_MODE)
00929 && (split_type != SPLT_OPTION_SILENCE_MODE)
00930 && (split_type != SPLT_OPTION_TRIM_SILENCE_MODE)
00931 && (split_type != SPLT_OPTION_ERROR_MODE))
00932 {
00933 splt_c_put_info_message_to_client(state,
00934 _(" Working with SILENCE AUTO-ADJUST (Threshold:"
00935 " %.1f dB Gap: %d sec Offset: %.2f)\n"),
00936 splt_o_get_float_option(state, SPLT_OPT_PARAM_THRESHOLD),
00937 splt_o_get_int_option(state, SPLT_OPT_PARAM_GAP),
00938 splt_o_get_float_option(state, SPLT_OPT_PARAM_OFFSET));
00939 }
00940 }
00941
00942 switch (split_type)
00943 {
00944 case SPLT_OPTION_WRAP_MODE:
00945 splt_s_wrap_split(state, &error);
00946 break;
00947 case SPLT_OPTION_SILENCE_MODE:
00948 splt_s_silence_split(state, &error);
00949 break;
00950 case SPLT_OPTION_TRIM_SILENCE_MODE:
00951 splt_s_trim_silence_split(state, &error);
00952 break;
00953 case SPLT_OPTION_TIME_MODE:
00954 splt_s_time_split(state, &error);
00955 break;
00956 case SPLT_OPTION_LENGTH_MODE:
00957 splt_s_equal_length_split(state, &error);
00958 break;
00959 case SPLT_OPTION_ERROR_MODE:
00960 splt_s_error_split(state, &error);
00961 break;
00962 default:
00963 if (split_type == SPLT_OPTION_NORMAL_MODE)
00964 {
00965 if (! splt_o_get_int_option(state, SPLT_OPT_PRETEND_TO_SPLIT))
00966 {
00967
00968 if (splt_t_get_splitnumber(state) < 2)
00969 {
00970 error = SPLT_ERROR_SPLITPOINTS;
00971 goto function_end;
00972 }
00973 }
00974
00975 splt_check_points_inf_song_length_and_convert_negatives(state, &error);
00976 if (error < 0) { goto function_end; }
00977
00978 splt_check_if_points_in_order(state, &error);
00979 if (error < 0) { goto function_end; }
00980 }
00981
00982 splt_s_normal_split(state, &error);
00983 break;
00984 }
00985
00986
00987 splt_p_end(state, &error);
00988
00989 function_end:
00990 if (new_filename_path)
00991 {
00992 free(new_filename_path);
00993 new_filename_path = NULL;
00994 }
00995
00996 splt_o_unlock_library(state);
00997 }
00998 else
00999 {
01000 error = SPLT_ERROR_LIBRARY_LOCKED;
01001 }
01002 }
01003 else
01004 {
01005 error = SPLT_ERROR_STATE_NULL;
01006 }
01007
01008 return error;
01009 }
01010
01014 void mp3splt_stop_split(splt_state *state, int *error)
01015 {
01016 int erro = SPLT_OK;
01017 int *err = &erro;
01018 if (error != NULL) { err = error; }
01019
01020 if (state != NULL)
01021 {
01022 splt_t_set_stop_split(state, SPLT_TRUE);
01023 }
01024 else
01025 {
01026 *err = SPLT_ERROR_STATE_NULL;
01027 }
01028 }
01029
01030
01031
01032
01039 void mp3splt_put_cue_splitpoints_from_file(splt_state *state,
01040 const char *file, int *error)
01041 {
01042 int erro = SPLT_OK;
01043 int *err = &erro;
01044 if (error != NULL) { err = error; }
01045
01046 if (state != NULL)
01047 {
01048 if (!splt_o_library_locked(state))
01049 {
01050 splt_o_lock_library(state);
01051
01052 splt_cue_put_splitpoints(file, state, err);
01053
01054 splt_o_unlock_library(state);
01055 }
01056 else
01057 {
01058 *err = SPLT_ERROR_LIBRARY_LOCKED;
01059 }
01060 }
01061 else
01062 {
01063 *err = SPLT_ERROR_STATE_NULL;
01064 }
01065 }
01066
01074 void mp3splt_put_cddb_splitpoints_from_file(splt_state *state,
01075 const char *file, int *error)
01076 {
01077 int erro = SPLT_OK;
01078 int *err = &erro;
01079 if (error != NULL) { err = error; }
01080
01081 if (state != NULL)
01082 {
01083 if (!splt_o_library_locked(state))
01084 {
01085 splt_o_lock_library(state);
01086
01087 splt_cddb_put_splitpoints(file, state, err);
01088
01089 splt_o_unlock_library(state);
01090 }
01091 else
01092 {
01093 *err = SPLT_ERROR_LIBRARY_LOCKED;
01094 }
01095 }
01096 else
01097 {
01098 *err = SPLT_ERROR_STATE_NULL;
01099 }
01100 }
01101
01109 void mp3splt_put_audacity_labels_splitpoints_from_file(splt_state *state,
01110 const char *file, int *error)
01111 {
01112 int erro = SPLT_OK;
01113 int *err = &erro;
01114 if (error != NULL) { err = error; }
01115
01116 if (state != NULL)
01117 {
01118 if (!splt_o_library_locked(state))
01119 {
01120 splt_o_lock_library(state);
01121
01122 splt_audacity_put_splitpoints(file, state, err);
01123
01124 splt_o_unlock_library(state);
01125 }
01126 else
01127 {
01128 *err = SPLT_ERROR_LIBRARY_LOCKED;
01129 }
01130 }
01131 else
01132 {
01133 *err = SPLT_ERROR_STATE_NULL;
01134 }
01135 }
01136
01137
01138
01139
01154 const splt_freedb_results *mp3splt_get_freedb_search(splt_state *state,
01155 const char *search_string,
01156 int *error,
01157 int search_type,
01158 const char search_server[256],
01159 int port)
01160 {
01161 int erro = SPLT_OK;
01162 int *err = &erro;
01163 if (error != NULL) { err = error; }
01164
01165 if (search_string == NULL)
01166 {
01167 *err = SPLT_FREEDB_NO_CD_FOUND;
01168 return NULL;
01169 }
01170
01171 if (state != NULL)
01172 {
01173
01174 char *search = strdup(search_string);
01175 if (search != NULL)
01176 {
01177 *err = splt_freedb_process_search(state, search, search_type,
01178 search_server, port);
01179
01180 free(search);
01181 search = NULL;
01182
01183 return state->fdb.search_results;
01184 }
01185 else
01186 {
01187 *err = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
01188 return NULL;
01189 }
01190 }
01191 else
01192 {
01193 *err = SPLT_ERROR_STATE_NULL;
01194 return NULL;
01195 }
01196 }
01197
01219 void mp3splt_write_freedb_file_result(splt_state *state, int disc_id,
01220 const char *cddb_file, int *error, int cddb_get_type,
01221 const char cddb_get_server[256], int port)
01222 {
01223 int erro = SPLT_OK;
01224 int *err = &erro;
01225 if (error != NULL) { err = error; }
01226
01227 if (state != NULL)
01228 {
01229 if (!splt_o_library_locked(state))
01230 {
01231 splt_o_lock_library(state);
01232
01233 char *freedb_file_content = NULL;
01234 freedb_file_content = splt_freedb_get_file(state, disc_id, err,
01235 cddb_get_type, cddb_get_server, port);
01236
01237
01238 if (*err == SPLT_FREEDB_FILE_OK)
01239 {
01240 if (! splt_o_get_int_option(state, SPLT_OPT_PRETEND_TO_SPLIT))
01241 {
01242
01243 FILE *output = NULL;
01244 if (!(output = splt_io_fopen(cddb_file, "w")))
01245 {
01246 splt_e_set_strerror_msg_with_data(state, cddb_file);
01247 *err = SPLT_ERROR_CANT_WRITE_TO_OUTPUT_FILE;
01248 }
01249 else
01250 {
01251 fprintf(output,"%s",freedb_file_content);
01252 if (fclose(output) != 0)
01253 {
01254 splt_e_set_strerror_msg_with_data(state, cddb_file);
01255 *err = SPLT_ERROR_CANNOT_CLOSE_FILE;
01256 }
01257 output = NULL;
01258 }
01259 }
01260 }
01261
01262
01263 if (freedb_file_content)
01264 {
01265 free(freedb_file_content);
01266 freedb_file_content = NULL;
01267 }
01268
01269 splt_o_unlock_library(state);
01270 }
01271 else
01272 {
01273 *err = SPLT_ERROR_LIBRARY_LOCKED;
01274 }
01275 }
01276 else
01277 {
01278 *err = SPLT_ERROR_STATE_NULL;
01279 }
01280 }
01281
01292 void mp3splt_export_to_cue(splt_state *state, const char *out_file,
01293 short stop_at_total_time, int *error)
01294 {
01295 int erro = SPLT_OK;
01296 int *err = &erro;
01297 if (error != NULL) { err = error; }
01298
01299 if (state != NULL)
01300 {
01301 if (!splt_o_library_locked(state))
01302 {
01303 splt_o_lock_library(state);
01304
01305 splt_cue_export_to_file(state, out_file, stop_at_total_time, err);
01306
01307 splt_o_unlock_library(state);
01308 }
01309 else
01310 {
01311 *err = SPLT_ERROR_LIBRARY_LOCKED;
01312 }
01313 }
01314 else
01315 {
01316 *err = SPLT_ERROR_STATE_NULL;
01317 }
01318 }
01319
01321 void mp3splt_set_oformat(splt_state *state,
01322 const char *format_string, int *error)
01323 {
01324 int erro = SPLT_OK;
01325 int *err = &erro;
01326 if (error != NULL) { err = error; }
01327
01328 if (state != NULL)
01329 {
01330 if (!splt_o_library_locked(state))
01331 {
01332 splt_o_lock_library(state);
01333
01334 splt_of_set_oformat(state, format_string, err, SPLT_FALSE);
01335
01336 splt_o_unlock_library(state);
01337 }
01338 else
01339 {
01340 *err = SPLT_ERROR_LIBRARY_LOCKED;
01341 }
01342 }
01343 else
01344 {
01345 *err = SPLT_ERROR_STATE_NULL;
01346 }
01347 }
01348
01349
01350
01351
01357 const splt_syncerrors *mp3splt_get_syncerrors(splt_state *state,
01358 int *error)
01359 {
01360 int erro = SPLT_OK;
01361 int *err = &erro;
01362 if (error != NULL) { err = error; }
01363
01364 if (state != NULL)
01365 {
01366 if (!splt_o_library_locked(state))
01367 {
01368 splt_o_lock_library(state);
01369
01370
01371 splt_check_file_type(state, err);
01372
01373 if (*err >= 0)
01374 {
01375 splt_o_lock_messages(state);
01376 splt_p_init(state, err);
01377 if (*err >= 0)
01378 {
01379 splt_o_unlock_messages(state);
01380 splt_p_search_syncerrors(state, err);
01381 splt_p_end(state, err);
01382 }
01383 else
01384 {
01385 splt_o_unlock_messages(state);
01386 }
01387 }
01388
01389 splt_o_unlock_library(state);
01390
01391 if (*err < 0)
01392 {
01393 return NULL;
01394 }
01395 }
01396 else
01397 {
01398 *err = SPLT_ERROR_LIBRARY_LOCKED;
01399 return NULL;
01400 }
01401
01402 return state->serrors;
01403 }
01404 else
01405 {
01406 *err = SPLT_ERROR_STATE_NULL;
01407 return NULL;
01408 }
01409 }
01410
01416 const splt_wrap *mp3splt_get_wrap_files(splt_state *state,
01417 int *error)
01418 {
01419 int erro = SPLT_OK;
01420 int *err = &erro;
01421 if (error != NULL) { err = error; }
01422
01423 if (state != NULL)
01424 {
01425 if (!splt_o_library_locked(state))
01426 {
01427 splt_o_lock_library(state);
01428
01429
01430 splt_check_file_type(state, err);
01431
01432 int old_split_mode = splt_o_get_int_option(state, SPLT_OPT_SPLIT_MODE);
01433 splt_o_set_int_option(state, SPLT_OPT_SPLIT_MODE, SPLT_OPTION_WRAP_MODE);
01434 if (*err >= 0)
01435 {
01436 splt_o_lock_messages(state);
01437 splt_p_init(state, err);
01438 if (*err >= 0)
01439 {
01440 splt_o_unlock_messages(state);
01441 splt_p_dewrap(state, SPLT_TRUE, NULL, err);
01442 splt_p_end(state, err);
01443 }
01444 else
01445 {
01446 splt_o_unlock_messages(state);
01447 }
01448 }
01449 splt_o_set_int_option(state, SPLT_OPT_SPLIT_MODE, old_split_mode);
01450
01451 splt_o_unlock_library(state);
01452 }
01453 else
01454 {
01455 *err = SPLT_ERROR_LIBRARY_LOCKED;
01456 }
01457
01458 return state->wrap;
01459 }
01460 else
01461 {
01462 *err = SPLT_ERROR_STATE_NULL;
01463 return NULL;
01464 }
01465 }
01466
01468 int mp3splt_set_silence_points(splt_state *state, int *error)
01469 {
01470 int erro = SPLT_OK;
01471 int *err = &erro;
01472 if (error != NULL) { err = error; }
01473
01474 int silence_mode = SPLT_OPTION_SILENCE_MODE;
01475 mp3splt_set_option(state, SPLT_OPT_SPLIT_MODE, &silence_mode);
01476
01477 int found_splitpoints = -1;
01478
01479 if (state != NULL)
01480 {
01481 if (!splt_o_library_locked(state))
01482 {
01483 splt_o_lock_library(state);
01484
01485 splt_t_set_stop_split(state, SPLT_FALSE);
01486
01487 splt_check_file_type(state, err);
01488
01489 if (*err >= 0)
01490 {
01491 splt_p_init(state, err);
01492 if (*err >= 0)
01493 {
01494 found_splitpoints = splt_s_set_silence_splitpoints(state, err);
01495 splt_p_end(state, err);
01496 }
01497 }
01498
01499 splt_o_unlock_library(state);
01500 }
01501 else
01502 {
01503 *err = SPLT_ERROR_LIBRARY_LOCKED;
01504 }
01505 }
01506 else
01507 {
01508 *err = SPLT_ERROR_STATE_NULL;
01509 }
01510
01511 return found_splitpoints;
01512 }
01513
01515 void mp3splt_set_trim_silence_points(splt_state *state, int *error)
01516 {
01517 int erro = SPLT_OK;
01518 int *err = &erro;
01519 if (error != NULL) { err = error; }
01520
01521 int silence_mode = SPLT_OPTION_TRIM_SILENCE_MODE;
01522 mp3splt_set_option(state, SPLT_OPT_SPLIT_MODE, &silence_mode);
01523
01524 if (state != NULL)
01525 {
01526 if (!splt_o_library_locked(state))
01527 {
01528 splt_o_lock_library(state);
01529
01530 splt_t_set_stop_split(state, SPLT_FALSE);
01531
01532 splt_check_file_type(state, err);
01533
01534 if (*err >= 0)
01535 {
01536 splt_p_init(state, err);
01537 if (*err >= 0)
01538 {
01539 splt_s_set_trim_silence_splitpoints(state, err);
01540 splt_p_end(state, err);
01541 }
01542 }
01543
01544 splt_o_unlock_library(state);
01545 }
01546 else
01547 {
01548 *err = SPLT_ERROR_LIBRARY_LOCKED;
01549 }
01550 }
01551 else
01552 {
01553 *err = SPLT_ERROR_STATE_NULL;
01554 }
01555 }
01556
01558 int mp3splt_count_silence_points(splt_state *state, int *error)
01559 {
01560 int number_of_tracks = mp3splt_set_silence_points(state, error) - 1;
01561
01562 return number_of_tracks;
01563 }
01564
01566 void mp3splt_get_version(char *version)
01567 {
01568 snprintf(version,20,"%s",SPLT_PACKAGE_VERSION);
01569 }
01570
01581 char *mp3splt_get_strerror(splt_state *state, int error_code)
01582 {
01583 return splt_e_strerror(state, error_code);
01584 }
01585
01592 int mp3splt_append_plugins_scan_dir(splt_state *state, char *dir)
01593 {
01594 return splt_p_append_plugin_scan_dir(state, dir);
01595 }
01596
01597 #ifdef __WIN32__
01598
01605 char *mp3splt_win32_utf16_to_utf8(const wchar_t *source)
01606 {
01607 return splt_w32_utf16_to_utf8(source);
01608 }
01609 #endif
01610
01623 char **mp3splt_find_filenames(splt_state *state, const char *filename,
01624 int *num_of_files_found, int *error)
01625 {
01626 int erro = SPLT_OK;
01627 int *err = &erro;
01628 if (error != NULL) { err = error; }
01629
01630 char **found_files = NULL;
01631
01632 if (state != NULL)
01633 {
01634 if (!splt_o_library_locked(state))
01635 {
01636 splt_o_lock_library(state);
01637
01638 *num_of_files_found = 0;
01639
01640 if (splt_io_check_if_file(state, filename))
01641 {
01642 if (splt_p_file_is_supported_by_plugins(state, filename))
01643 {
01644 found_files = malloc(sizeof(char *));
01645 if (!found_files)
01646 {
01647 *err = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
01648 return NULL;
01649 }
01650
01651 int fname_size = strlen(filename) + 1;
01652 found_files[0] = malloc(sizeof(char) * fname_size);
01653 memset(found_files[0], '\0', fname_size);
01654
01655 if (!found_files[0])
01656 {
01657 free(found_files);
01658 return NULL;
01659 }
01660
01661 strncat(found_files[0], filename, fname_size);
01662 *num_of_files_found = 1;
01663 }
01664 }
01665 else
01666 {
01667 char *dir = strdup(filename);
01668 if (dir == NULL)
01669 {
01670 *err = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
01671 return NULL;
01672 }
01673
01674 if (dir[strlen(dir)-1] == SPLT_DIRCHAR)
01675 {
01676 dir[strlen(dir)-1] = '\0';
01677 }
01678
01679 splt_io_find_filenames(state, dir, &found_files, num_of_files_found, err);
01680
01681 if (dir)
01682 {
01683 free(dir);
01684 dir = NULL;
01685 }
01686 }
01687
01688 splt_o_unlock_library(state);
01689 }
01690 else
01691 {
01692 *err = SPLT_ERROR_LIBRARY_LOCKED;
01693 }
01694 }
01695 else
01696 {
01697 *err = SPLT_ERROR_STATE_NULL;
01698 return NULL;
01699 }
01700
01701 return found_files;
01702 }
01703
01705
01707 int mp3splt_u_check_if_directory(const char *fname)
01708 {
01709 return splt_io_check_if_directory(fname);
01710 }
01711
01712 void mp3splt_free_one_tag(splt_tags *tags)
01713 {
01714 splt_tu_free_one_tags(&tags);
01715 }
01716
01717 splt_tags *mp3splt_parse_filename_regex(splt_state *state, int *error)
01718 {
01719 splt_tags *tags = NULL;
01720 int erro = SPLT_OK;
01721 int *err = &erro;
01722 if (error != NULL) { err = error; }
01723
01724 if (state != NULL)
01725 {
01726 if (!splt_o_library_locked(state))
01727 {
01728 splt_o_lock_library(state);
01729
01730 #ifndef NO_PCRE
01731 tags = splt_fr_parse_from_state(state, error);
01732 #else
01733 splt_c_put_info_message_to_client(state,
01734 _(" warning: cannot set tags from filename regular expression - compiled without pcre support\n"));
01735 *error = SPLT_REGEX_UNAVAILABLE;
01736 #endif
01737
01738 splt_o_unlock_library(state);
01739 }
01740 else
01741 {
01742 *err = SPLT_ERROR_LIBRARY_LOCKED;
01743 }
01744 }
01745 else
01746 {
01747 *err = SPLT_ERROR_STATE_NULL;
01748 }
01749
01750 return tags;
01751 }
01752