foobar2000 SDK  2015-08-03
decode.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 
4 public:
6  void on_init(HWND p_wnd) {}
7  void run(threaded_process_status & p_status,abort_callback & p_abort) {
8  try {
9  const t_uint32 decode_flags = input_flag_no_seeking | input_flag_no_looping; // tell the decoders that we won't seek and that we don't want looping on formats that support looping.
10  input_helper input;
11  for(t_size walk = 0; walk < m_items.get_size(); ++walk) {
12  p_abort.check(); // in case the input we're working with fails at doing this
13  p_status.set_progress(walk, m_items.get_size());
14  p_status.set_progress_secondary(0);
15  p_status.set_item_path( m_items[walk]->get_path() );
16  input.open(NULL, m_items[walk], decode_flags, p_abort);
17 
18  double length;
19  { // fetch the track length for proper dual progress display;
21  // input.open should have preloaded relevant info, no need to query the input itself again.
22  // Regular get_info() may not retrieve freshly loaded info yet at this point (it will start giving the new info when relevant info change callbacks are dispatched); we need to use get_info_async.
23  if (m_items[walk]->get_info_async(info)) length = info.get_length();
24  else length = 0;
25  }
26 
28  double decoded = 0;
29  while(input.run(l_chunk, p_abort)) { // main decode loop
30  m_peak = l_chunk.get_peak(m_peak);
31  if (length > 0) { // don't bother for unknown length tracks
32  decoded += l_chunk.get_duration();
33  if (decoded > length) decoded = length;
34  p_status.set_progress_secondary_float(decoded / length);
35  }
36  p_abort.check(); // in case the input we're working with fails at doing this
37  }
38  }
39  } catch(std::exception const & e) {
40  m_failMsg = e.what();
41  }
42  }
43  void on_done(HWND p_wnd,bool p_was_aborted) {
44  if (!p_was_aborted) {
45  if (!m_failMsg.is_empty()) {
46  popup_message::g_complain("Peak scan failure", m_failMsg);
47  } else {
48  pfc::string_formatter result;
49  result << "Value: " << m_peak << "\n\n";
50  result << "Scanned items:\n";
51  for(t_size walk = 0; walk < m_items.get_size(); ++walk) {
52  result << m_items[walk] << "\n";
53  }
54  popup_message::g_show(result,"Peak scan result");
55  }
56  }
57  }
58 private:
62 };
63 
65  try {
66  if (data.get_count() == 0) throw pfc::exception_invalid_params();
68  static_api_ptr_t<threaded_process>()->run_modeless(
69  cb,
72  "Sample component: peak scan");
73  } catch(std::exception const & e) {
74  popup_message::g_complain("Could not start peak scan process", e);
75  }
76 }
void on_init(HWND p_wnd)
Called from the main thread before spawning the worker thread. Note that you should not access the w...
Definition: decode.cpp:6
Implementation of audio_chunk. Takes pfc allocator template as template parameter.
Definition: audio_chunk.h:242
audio_sample get_peak(audio_sample p_peak) const
Helper, calculates peak value of data in the chunk. The optional parameter specifies initial peak val...
Template implementing reference-counting features of service_base. Intended for dynamic instantiation...
Definition: service_impl.h:4
Shows the item being currently processed.
void RunCalculatePeak(metadb_handle_list_cref data)
Definition: decode.cpp:64
double get_length() const
Retrieves audio duration, in seconds. Note that the reported duration should not be assumed to be th...
audio_sample m_peak
Definition: decode.cpp:59
void run(threaded_process_status &p_status, abort_callback &p_abort)
Called from the worker thread. Do all the hard work here.
Definition: decode.cpp:7
t_size get_size() const
Definition: list.h:366
virtual void set_progress_secondary(t_size p_state)=0
Sets the secondary progress bar state; scale from progress_min to progress_max.
Callback class passed to your threaded_process client code; allows you to give various visual feedbac...
pfc::string8 m_failMsg
Definition: decode.cpp:60
void info(const char *p_message)
Definition: console.cpp:4
void set_progress_secondary_float(double p_state)
Helper; sets secondary progress with a float 0..1 scale.
virtual void set_item_path(const char *p_item, t_size p_item_len=~0)=0
Sets the currently progressed item label; treats the label as a file path.
bool run(audio_chunk &p_chunk, abort_callback &p_abort)
calculate_peak_process(metadb_handle_list_cref items)
Definition: decode.cpp:5
size_t t_size
Definition: int_types.h:48
string8_fastalloc string_formatter
Definition: string_base.h:615
Shows dual progress bars; implies flag_show_progress.
virtual t_size get_count() const =0
const metadb_handle_list m_items
Definition: decode.cpp:61
Callback class for the threaded_process API. You must implement this to create your own threaded_proc...
void open(service_ptr_t< file > p_filehint, metadb_handle_ptr p_location, unsigned p_flags, abort_callback &p_abort, bool p_from_redirect=false, bool p_skip_hints=false)
bool is_empty() const
Definition: string_base.h:213
static void g_show(const char *p_msg, const char *p_title, t_icon p_icon=icon_information)
Static helper function instantiating the service and activating the message dialog. See show() for description of parameters.
Definition: popup_message.h:26
float audio_sample
Definition: audio_sample.h:6
std::exception exception
Definition: primitives.h:193
HWND get_main_window()
Retrieves main app window. WARNING: this is provided for parent of dialog windows and such only; usin...
Shows the "abort" button.
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
static void g_complain(const char *what)
Implements file_info.
virtual void set_progress(t_size p_state)=0
Sets the primary progress bar state; scale from progress_min to progress_max.
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition: service.h:533
double get_duration() const
Retrieves duration of contained audio data, in seconds.
Definition: audio_chunk.h:116
void on_done(HWND p_wnd, bool p_was_aborted)
Called after the worker thread has finished executing.
Definition: decode.cpp:43
uint32_t t_uint32
Definition: int_types.h:5