foobar2000 SDK  2015-08-03
cuesheet_index_list.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 
3 #ifndef _MSC_VER
4 #define sprintf_s sprintf
5 #endif
6 
8  if (m_positions[1] < m_positions[0]) return false;
9  for(t_size n = 2; n < count && m_positions[n] > 0; n++) {
10  if (m_positions[n] < m_positions[n-1]) return false;
11  }
12  return true;
13 }
14 
16 {
17  double base = m_positions[1];
18 
19  if (base > 0) {
20  p_out.info_set("referenced_offset",cuesheet_format_index_time(base));
21  }
22 
23  if (m_positions[0] < base)
24  p_out.info_set("pregap",cuesheet_format_index_time(base - m_positions[0]));
25  else
26  p_out.info_remove("pregap");
27 
28  p_out.info_remove("index 00");
29  p_out.info_remove("index 01");
30 
31  for(unsigned n=2;n<count;n++)
32  {
33  char namebuffer[16];
34  sprintf_s(namebuffer,"index %02u",n);
35  double position = m_positions[n] - base;
36  if (position > 0)
37  p_out.info_set(namebuffer,cuesheet_format_index_time(position));
38  else
39  p_out.info_remove(namebuffer);
40  }
41 }
42 
43 static bool parse_value(const char * p_name,double & p_out)
44 {
45  if (p_name == NULL) return false;
46  try {
47  p_out = cuesheet_parse_index_time_e(p_name,strlen(p_name));
48  } catch(std::exception const &) {return false;}
49  return true;
50 }
51 
52 bool t_cuesheet_index_list::from_infos(file_info const & p_in,double p_base)
53 {
54  double pregap;
55  bool found = false;
56  if (!parse_value(p_in.info_get("pregap"),pregap)) pregap = 0;
57  else found = true;
58  m_positions[0] = p_base - pregap;
59  m_positions[1] = p_base;
60  for(unsigned n=2;n<count;n++)
61  {
62  char namebuffer[16];
63  sprintf_s(namebuffer,"index %02u",n);
64  double temp;
65  if (parse_value(p_in.info_get(namebuffer),temp)) {
66  m_positions[n] = temp + p_base; found = true;
67  } else {
68  m_positions[n] = 0;
69  }
70  }
71  return found;
72 }
73 
75  for(unsigned n=0;n<count;n++) if (m_positions[n] != m_positions[1]) return false;
76  return true;
77 }
const char * info_get(const char *p_name) const
Definition: file_info.h:171
void to_infos(file_info &p_out) const
bool info_remove(const char *p_name)
Definition: file_info.h:170
static bool parse_value(const char *p_name, double &p_out)
Main interface class for information about some playable object.
Definition: file_info.h:73
bool from_infos(file_info const &p_in, double p_base)
size_t t_size
Definition: int_types.h:48
t_size info_set(const char *p_name, const char *p_value)
Definition: file_info.h:167
std::exception exception
Definition: primitives.h:193
double cuesheet_parse_index_time_e(const char *p_string, t_size p_length)
Definition: chapterizer.cpp:43