foobar2000 SDK  2015-01-14
Public Member Functions | Private Attributes
calculate_peak_process
+ Inheritance diagram for calculate_peak_process:

Public Member Functions

 calculate_peak_process (metadb_handle_list_cref items)
 
void on_done (HWND p_wnd, bool p_was_aborted)
 
void on_init (HWND p_wnd)
 
void run (threaded_process_status &p_status, abort_callback &p_abort)
 
- Public Member Functions inherited from threaded_process_callback
 FB2K_MAKE_SERVICE_INTERFACE (threaded_process_callback, service_base)
 
- Public Member Functions inherited from service_base
template<typename outPtr_t >
bool cast (outPtr_t &outPtr)
 
virtual int service_add_ref ()=0 throw ()
 
virtual bool service_query (service_ptr_t< service_base > &p_out, const GUID &p_guid)
 
template<class T >
bool service_query_t (service_ptr_t< T > &p_out)
 
virtual int service_release ()=0 throw ()
 

Private Attributes

pfc::string8 m_failMsg
 
const metadb_handle_list m_items
 
audio_sample m_peak
 

Additional Inherited Members

- Public Types inherited from service_base
typedef service_base t_interface
 
- Protected Member Functions inherited from service_base
 service_base ()
 
 ~service_base ()
 

Detailed Description

Definition at line 3 of file decode.cpp.

Constructor & Destructor Documentation

calculate_peak_process::calculate_peak_process ( metadb_handle_list_cref  items)
inline

Definition at line 5 of file decode.cpp.

5 : m_items(items), m_peak() {}
audio_sample m_peak
Definition: decode.cpp:59
const metadb_handle_list m_items
Definition: decode.cpp:61

Member Function Documentation

void calculate_peak_process::on_done ( HWND  p_wnd,
bool  p_was_aborted 
)
inlinevirtual

Called after the worker thread has finished executing.

Reimplemented from threaded_process_callback.

Definition at line 43 of file decode.cpp.

43  {
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  }
audio_sample m_peak
Definition: decode.cpp:59
t_size get_size() const
Definition: list.h:366
pfc::string8 m_failMsg
Definition: decode.cpp:60
size_t t_size
Definition: int_types.h:48
string8_fastalloc string_formatter
Definition: string_base.h:614
const metadb_handle_list m_items
Definition: decode.cpp:61
bool is_empty() const
Definition: string_base.h:212
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
static void g_complain(const char *what)
void calculate_peak_process::on_init ( HWND  p_wnd)
inlinevirtual

Called from the main thread before spawning the worker thread.
Note that you should not access the window handle passed to on_init() in the worker thread later on.

Reimplemented from threaded_process_callback.

Definition at line 6 of file decode.cpp.

6 {}
void calculate_peak_process::run ( threaded_process_status p_status,
abort_callback p_abort 
)
inlinevirtual

Called from the worker thread. Do all the hard work here.

Implements threaded_process_callback.

Definition at line 7 of file decode.cpp.

7  {
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  }
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...
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
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.
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)
size_t t_size
Definition: int_types.h:48
const metadb_handle_list m_items
Definition: decode.cpp:61
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)
std::exception exception
Definition: primitives.h:193
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.
double get_duration() const
Retrieves duration of contained audio data, in seconds.
Definition: audio_chunk.h:116
uint32_t t_uint32
Definition: int_types.h:5

Field Documentation

pfc::string8 calculate_peak_process::m_failMsg
private

Definition at line 60 of file decode.cpp.

const metadb_handle_list calculate_peak_process::m_items
private

Definition at line 61 of file decode.cpp.

audio_sample calculate_peak_process::m_peak
private

Definition at line 59 of file decode.cpp.


The documentation for this class was generated from the following file: