foobar2000 SDK  2015-08-03
chapterizer.cpp
Go to the documentation of this file.
1 #include "foobar2000.h"
2 
3 void chapter_list::copy(const chapter_list & p_source)
4 {
5  t_size n, count = p_source.get_chapter_count();
6  set_chapter_count(count);
7  for(n=0;n<count;n++) set_info(n,p_source.get_info(n));
8  set_pregap(p_source.get_pregap());
9 }
10 
11 bool chapterizer::g_find(service_ptr_t<chapterizer> & p_out,const char * p_path)
12 {
15  while(e.next(ptr)) {
16  if (ptr->is_our_path(p_path)) {
17  p_out = ptr;
18  return true;
19  }
20  }
21  return false;
22 }
23 
24 bool chapterizer::g_is_pregap_capable(const char * p_path) {
27  while(e.next(ptr)) {
28  if (ptr->supports_pregaps() && ptr->is_our_path(p_path)) {
29  return true;
30  }
31  }
32  return false;
33 }
34 
36 {
37  t_uint64 ticks = audio_math::time_to_samples(p_time,75);
38  t_uint64 seconds = ticks / 75; ticks %= 75;
39  t_uint64 minutes = seconds / 60; seconds %= 60;
40  m_buffer << pfc::format_uint(minutes,2) << ":" << pfc::format_uint(seconds,2) << ":" << pfc::format_uint(ticks,2);
41 }
42 
43 double cuesheet_parse_index_time_e(const char * p_string,t_size p_length)
44 {
45  return (double) cuesheet_parse_index_time_ticks_e(p_string,p_length) / 75.0;
46 }
47 
48 unsigned cuesheet_parse_index_time_ticks_e(const char * p_string,t_size p_length)
49 {
50  p_length = pfc::strlen_max(p_string,p_length);
51  t_size ptr = 0;
52  t_size splitmarks[2];
53  t_size splitptr = 0;
54  for(ptr=0;ptr<p_length;ptr++)
55  {
56  if (p_string[ptr] == ':')
57  {
58  if (splitptr >= 2) throw std::runtime_error("invalid INDEX time syntax");
59  splitmarks[splitptr++] = ptr;
60  }
61  else if (!pfc::char_is_numeric(p_string[ptr])) throw std::runtime_error("invalid INDEX time syntax");
62  }
63 
64  t_size minutes_base = 0, minutes_length = 0, seconds_base = 0, seconds_length = 0, frames_base = 0, frames_length = 0;
65 
66  switch(splitptr)
67  {
68  case 0:
69  frames_base = 0;
70  frames_length = p_length;
71  break;
72  case 1:
73  seconds_base = 0;
74  seconds_length = splitmarks[0];
75  frames_base = splitmarks[0] + 1;
76  frames_length = p_length - frames_base;
77  break;
78  case 2:
79  minutes_base = 0;
80  minutes_length = splitmarks[0];
81  seconds_base = splitmarks[0] + 1;
82  seconds_length = splitmarks[1] - seconds_base;
83  frames_base = splitmarks[1] + 1;
84  frames_length = p_length - frames_base;
85  break;
86  }
87 
88  unsigned ret = 0;
89 
90  if (frames_length > 0) ret += pfc::atoui_ex(p_string + frames_base,frames_length);
91  if (seconds_length > 0) ret += 75 * pfc::atoui_ex(p_string + seconds_base,seconds_length);
92  if (minutes_length > 0) ret += 60 * 75 * pfc::atoui_ex(p_string + minutes_base,minutes_length);
93 
94  return ret;
95 }
96 
Interface for object storing list of chapters.
Definition: chapterizer.h:2
static bool g_find(service_ptr_t< chapterizer > &p_out, const char *p_path)
Static helper, tries to find chapterizer interface that supports specified file.
Definition: chapterizer.cpp:11
uint64_t t_uint64
Definition: int_types.h:3
virtual const file_info & get_info(t_size p_chapter) const =0
Queries description of specified chapter.
virtual void set_info(t_size p_chapter, const file_info &p_info)=0
Modifies description of specified chapter.
static bool g_is_pregap_capable(const char *p_path)
Definition: chapterizer.cpp:24
t_size strlen_max(const char *ptr, t_size max)
Definition: string_base.h:91
size_t t_size
Definition: int_types.h:48
virtual void set_chapter_count(t_size p_count)=0
Sets number of chapters.
virtual t_size get_chapter_count() const =0
Returns number of chapters.
virtual double get_pregap() const =0
unsigned atoui_ex(const char *p_string, t_size p_string_len)
unsigned cuesheet_parse_index_time_ticks_e(const char *p_string, t_size p_length)
Definition: chapterizer.cpp:48
virtual void set_pregap(double val)=0
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
bool char_is_numeric(char_t p_char)
Definition: string_base.h:99
double cuesheet_parse_index_time_e(const char *p_string, t_size p_length)
Definition: chapterizer.cpp:43
bool next(service_ptr_t< t_query > &p_out)
Definition: service.h:587
cuesheet_format_index_time(double p_time)
Definition: chapterizer.cpp:35
void copy(const chapter_list &p_source)
Copies contents of specified chapter_list object to this object.
Definition: chapterizer.cpp:3