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
00038 #include <string.h>
00039
00040 #include "splt.h"
00041
00042 int splt_sp_splitpoint_exists(splt_state *state, int index)
00043 {
00044 if ((index >= 0) && (index < state->split.real_splitnumber))
00045 {
00046 return SPLT_TRUE;
00047 }
00048 else
00049 {
00050 return SPLT_FALSE;
00051 }
00052 }
00053
00054 int splt_sp_append_splitpoint(splt_state *state, long split_value,
00055 const char *name, int type)
00056 {
00057 int error = SPLT_OK;
00058
00059 splt_struct *split = &state->split;
00060
00061 splt_d_print_debug(state,"Appending splitpoint _%s_ with value _%ld_\n",
00062 name, split_value);
00063
00064 split->real_splitnumber++;
00065
00066 if (!split->points)
00067 {
00068 if ((split->points = malloc(sizeof(splt_point))) == NULL)
00069 {
00070 return SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00071 }
00072 }
00073 else
00074 {
00075 if ((split->points = realloc(split->points,
00076 split->real_splitnumber * sizeof(splt_point))) == NULL)
00077 {
00078 return SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00079 }
00080 }
00081
00082 int index = split->real_splitnumber - 1;
00083 split->points[index].name = NULL;
00084
00085 error = splt_sp_set_splitpoint_value(state, index, split_value);
00086 if (error != SPLT_OK) { return error; }
00087
00088 error = splt_sp_set_splitpoint_name(state, index, name);
00089 if (error < 0) { return error; }
00090
00091 splt_sp_set_splitpoint_type(state, index, type);
00092
00093 return error;
00094 }
00095
00096 splt_point *splt_sp_get_splitpoints(splt_state *state, int *splitpoints_number)
00097 {
00098 splt_struct *split = &state->split;
00099 *splitpoints_number = split->real_splitnumber;
00100 return split->points;
00101 }
00102
00103 void splt_sp_free_splitpoints(splt_state *state)
00104 {
00105 splt_struct *split = &state->split;
00106
00107 if (split->points)
00108 {
00109 int i = 0;
00110 for (i = 0; i < split->real_splitnumber; i++)
00111 {
00112 if (split->points[i].name)
00113 {
00114 free(split->points[i].name);
00115 split->points[i].name = NULL;
00116 }
00117 }
00118
00119 free(split->points);
00120 split->points = NULL;
00121 }
00122
00123 split->splitnumber = 0;
00124 split->real_splitnumber = 0;
00125 }
00126
00127 int splt_sp_set_splitpoint_value(splt_state *state, int index, long split_value)
00128 {
00129 splt_d_print_debug(state,"Splitpoint at _%d_ is %ld_\n", index, split_value);
00130
00131 int error = SPLT_OK;
00132
00133 if ((index >= 0) &&
00134 (index < state->split.real_splitnumber))
00135 {
00136 state->split.points[index].value = split_value;
00137 }
00138 else
00139 {
00140 splt_e_error(SPLT_IERROR_INT,__func__, index, NULL);
00141 }
00142
00143 return error;
00144 }
00145
00146 int splt_sp_set_splitpoint_name(splt_state *state, int index, const char *name)
00147 {
00148 splt_d_print_debug(state,"Splitpoint name at _%d_ is _%s_\n", index, name);
00149
00150 int error = SPLT_OK;
00151 splt_point *points = state->split.points;
00152
00153 if ((index >= 0) && (index < state->split.real_splitnumber))
00154 {
00155 error = splt_su_copy(name, &points[index].name);
00156 }
00157 else
00158 {
00159 splt_e_error(SPLT_IERROR_INT,__func__, index, NULL);
00160 }
00161
00162 return error;
00163 }
00164
00165 int splt_sp_set_splitpoint_type(splt_state *state, int index, int type)
00166 {
00167 int error = SPLT_OK;
00168
00169 if ((index >= 0) && (index < state->split.real_splitnumber))
00170 {
00171 state->split.points[index].type = type;
00172 }
00173 else
00174 {
00175 splt_e_error(SPLT_IERROR_INT, __func__, index, NULL);
00176 }
00177
00178 return error;
00179 }
00180
00181 long splt_sp_get_splitpoint_value(splt_state *state, int index, int *error)
00182 {
00183 if ((index >= 0) && (index < state->split.real_splitnumber))
00184 {
00185 return state->split.points[index].value;
00186 }
00187 else
00188 {
00189 splt_e_error(SPLT_IERROR_INT, __func__, index, NULL);
00190 return -1;
00191 }
00192 }
00193
00194 const char *splt_sp_get_splitpoint_name(splt_state *state, int index, int *error)
00195 {
00196 if ((index >= 0) && (index < state->split.real_splitnumber))
00197 {
00198 return state->split.points[index].name;
00199 }
00200 else
00201 {
00202
00203 return NULL;
00204 }
00205 }
00206
00207 int splt_sp_get_splitpoint_type(splt_state *state, int index, int *error)
00208 {
00209 if ((index >= 0) && (index < state->split.real_splitnumber))
00210 {
00211 return state->split.points[index].type;
00212 }
00213 else
00214 {
00215
00216
00217 return 1;
00218 }
00219 }
00220
00221 void splt_sp_get_mins_secs_hundr_from_splitpoint(long splitpoint,
00222 long *mins, long *secs, long *hundr)
00223 {
00224 if (hundr)
00225 {
00226 *hundr = splitpoint % 100;
00227 }
00228
00229 splitpoint /= 100;
00230
00231 if (secs)
00232 {
00233 *secs = splitpoint % 60;
00234 }
00235
00236 if (mins)
00237 {
00238 *mins = splitpoint / 60;
00239 }
00240 }
00241
00242 int splt_sp_cut_splitpoint_extension(splt_state *state, int index)
00243 {
00244 int error = SPLT_OK;
00245
00246 if (splt_sp_splitpoint_exists(state,index))
00247 {
00248 const char *temp_name = splt_sp_get_splitpoint_name(state, index, &error);
00249 if (error < 0) { return error; }
00250
00251 if (temp_name)
00252 {
00253 char *new_name = NULL;
00254 error = splt_su_copy(temp_name, &new_name);
00255 if (error < 0) { return error; }
00256
00257 splt_su_cut_extension(new_name);
00258 error = splt_sp_set_splitpoint_name(state, index, new_name);
00259
00260 free(new_name);
00261 new_name = NULL;
00262 }
00263 }
00264
00265 return error;
00266 }
00267
00268 static int splt_point_value_sort(const void *p1, const void *p2)
00269 {
00270 splt_point *point1 = (splt_point *)p1;
00271 splt_point *point2 = (splt_point *)p2;
00272
00273 return point1->value - point2->value;
00274 }
00275
00276 void splt_sp_order_splitpoints(splt_state *state, int len)
00277 {
00278 qsort(state->split.points, state->split.real_splitnumber,
00279 sizeof *state->split.points, splt_point_value_sort);
00280 }
00281
00282 void splt_sp_skip_minimum_track_length_splitpoints(splt_state *state, int *error)
00283 {
00284 if (state->split.real_splitnumber <= 0) { return; }
00285
00286 long min_track_length =
00287 splt_co_time_to_long(splt_o_get_float_option(state, SPLT_OPT_PARAM_MIN_TRACK_LENGTH));
00288
00289 int i = 1;
00290 for (i = 1;i < state->split.real_splitnumber; i++)
00291 {
00292 int begin_index = i-1;
00293 int end_index = i;
00294
00295 int begin_point_type = splt_sp_get_splitpoint_type(state, begin_index, error);
00296 if (*error < 0) { return; }
00297
00298 if (begin_point_type == SPLT_SKIPPOINT)
00299 {
00300 continue;
00301 }
00302
00303 long begin_track_point = splt_sp_get_splitpoint_value(state, begin_index, error);
00304 if (*error < 0) { return; }
00305 long end_track_point = splt_sp_get_splitpoint_value(state, end_index, error);
00306 if (*error < 0) { return; }
00307
00308 long track_length = end_track_point - begin_track_point;
00309 if (track_length >= min_track_length)
00310 {
00311 continue;
00312 }
00313
00314 long mins1, secs1, hundr1;
00315 splt_co_get_mins_secs_hundr(track_length, &mins1, &secs1, &hundr1);
00316 long mins2, secs2, hundr2;
00317 splt_co_get_mins_secs_hundr(min_track_length, &mins2, &secs2, &hundr2);
00318
00319 splt_c_put_info_message_to_client(state,
00320 _(" info: track too short (%ld.%ld.%ld < %ld.%ld.%ld); skipped.\n"),
00321 mins1, secs1, hundr1, mins2, secs2, hundr2);
00322
00323 splt_sp_set_splitpoint_type(state, begin_index, SPLT_SKIPPOINT);
00324 }
00325 }
00326
00327 long splt_sp_overlap_time(splt_state *state, int splitpoint_index)
00328 {
00329 int error = SPLT_OK;
00330 long split_value = splt_sp_get_splitpoint_value(state, splitpoint_index, &error);
00331 long overlap_time = splt_o_get_long_option(state, SPLT_OPT_OVERLAP_TIME);
00332 if ((overlap_time > 0) && (split_value != LONG_MAX))
00333 {
00334 long overlapped_split_value = split_value + overlap_time;
00335 long total_time = splt_t_get_total_time(state);
00336 if ((total_time > 0) && (overlapped_split_value > total_time))
00337 {
00338 overlapped_split_value = total_time;
00339 }
00340
00341 splt_sp_set_splitpoint_value(state, splitpoint_index, overlapped_split_value);
00342
00343 return overlapped_split_value;
00344 }
00345
00346 return split_value;
00347 }
00348