foobar2000 SDK  2015-08-03
play_callback.h
Go to the documentation of this file.
1 
5 class NOVTABLE play_callback {
6 public:
8  virtual void FB2KAPI on_playback_starting(play_control::t_track_command p_command,bool p_paused) = 0;
10  virtual void FB2KAPI on_playback_new_track(metadb_handle_ptr p_track) = 0;
12  virtual void FB2KAPI on_playback_stop(play_control::t_stop_reason p_reason) = 0;
14  virtual void FB2KAPI on_playback_seek(double p_time) = 0;
16  virtual void FB2KAPI on_playback_pause(bool p_state) = 0;
18  virtual void FB2KAPI on_playback_edited(metadb_handle_ptr p_track) = 0;
20  virtual void FB2KAPI on_playback_dynamic_info(const file_info & p_info) = 0;
22  virtual void FB2KAPI on_playback_dynamic_info_track(const file_info & p_info) = 0;
24  virtual void FB2KAPI on_playback_time(double p_time) = 0;
27  virtual void FB2KAPI on_volume_change(float p_new_val) = 0;
28 
29  enum {
30  flag_on_playback_starting = 1 << 0,
31  flag_on_playback_new_track = 1 << 1,
32  flag_on_playback_stop = 1 << 2,
33  flag_on_playback_seek = 1 << 3,
34  flag_on_playback_pause = 1 << 4,
35  flag_on_playback_edited = 1 << 5,
36  flag_on_playback_dynamic_info = 1 << 6,
37  flag_on_playback_dynamic_info_track = 1 << 7,
38  flag_on_playback_time = 1 << 8,
39  flag_on_volume_change = 1 << 9,
40 
41  flag_on_playback_all = flag_on_playback_starting | flag_on_playback_new_track |
42  flag_on_playback_stop | flag_on_playback_seek |
43  flag_on_playback_pause | flag_on_playback_edited |
44  flag_on_playback_dynamic_info | flag_on_playback_dynamic_info_track | flag_on_playback_time,
45  };
46 protected:
49 };
50 
54 class NOVTABLE play_callback_manager : public service_base
55 {
56 public:
61  virtual void FB2KAPI register_callback(play_callback * p_callback,unsigned p_flags,bool p_forward_status_on_register) = 0;
64  virtual void FB2KAPI unregister_callback(play_callback * p_callback) = 0;
65 
66  FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(play_callback_manager);
67 };
68 
71 public:
72  play_callback_impl_base(unsigned p_flags = ~0) {
73  static_api_ptr_t<play_callback_manager>()->register_callback(this,p_flags,false);
74  }
76  static_api_ptr_t<play_callback_manager>()->unregister_callback(this);
77  }
78  void play_callback_reregister(unsigned flags, bool refresh = false) {
80  api->unregister_callback(this);
81  api->register_callback(this,flags,refresh);
82  }
83  void on_playback_starting(play_control::t_track_command p_command,bool p_paused) {}
86  void on_playback_seek(double p_time) {}
87  void on_playback_pause(bool p_state) {}
89  void on_playback_dynamic_info(const file_info & p_info) {}
90  void on_playback_dynamic_info_track(const file_info & p_info) {}
91  void on_playback_time(double p_time) {}
92  void on_volume_change(float p_new_val) {}
93 
94  PFC_CLASS_NOT_COPYABLE_EX(play_callback_impl_base)
95 };
96 
99 public:
101  virtual unsigned get_flags() = 0;
102 
103  FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(play_callback_static);
104 };
105 
106 template<typename T>
108 
109 
113 public:
114  virtual void on_item_played(metadb_handle_ptr p_item) = 0;
115 
116  FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(playback_statistics_collector);
117 };
118 
119 template<typename T>
121 
122 
123 
124 
127 public:
129 
131  t_uint32 flags = flag_on_playback_starting | flag_on_playback_new_track | flag_on_playback_stop | flag_on_playback_pause | flag_on_playback_edited | flag_on_volume_change;
132  if (level >= playback_control::display_level_titles) flags |= flag_on_playback_dynamic_info_track;
133  if (level >= playback_control::display_level_all) flags |= flag_on_playback_seek | flag_on_playback_dynamic_info | flag_on_playback_time;
134  return flags;
135  }
136 protected:
137  virtual void on_playback_event() {}
138 private:
139  void on_playback_starting(play_control::t_track_command p_command,bool p_paused) {on_playback_event();}
140  void on_playback_new_track(metadb_handle_ptr p_track) {on_playback_event();}
141  void on_playback_stop(play_control::t_stop_reason p_reason) {on_playback_event();}
142  void on_playback_seek(double p_time) {on_playback_event();}
143  void on_playback_pause(bool p_state) {on_playback_event();}
144  void on_playback_edited(metadb_handle_ptr p_track) {on_playback_event();}
145  void on_playback_dynamic_info(const file_info & p_info) {on_playback_event();}
146  void on_playback_dynamic_info_track(const file_info & p_info) {on_playback_event();}
147  void on_playback_time(double p_time) {on_playback_event();}
148  void on_volume_change(float p_new_val) {on_playback_event();}
149 };
150 
152 public:
153  playback_volume_notify() : play_callback_impl_base(flag_on_volume_change) {}
154  // override me
155  void on_volume_change(float p_new_val) {}
156 };
void on_playback_dynamic_info(const file_info &p_info)
Dynamic info (VBR bitrate etc) change.
void on_volume_change(float p_new_val)
User changed volume settings. Possibly called when not playing.
static t_uint32 GrabCBFlags(playback_control::t_display_level level)
Implementation helper.
Definition: play_callback.h:70
display_level_basic + dynamic track titles on e.g. live streams
void on_playback_new_track(metadb_handle_ptr p_track)
Playback advanced to new track.
void on_playback_seek(double p_time)
User has seeked to specific time.
play_callback_impl_base(unsigned p_flags=~0)
Definition: play_callback.h:72
void on_playback_time(double p_time)
Called every second, for time display.
Definition: play_callback.h:91
void on_playback_starting(play_control::t_track_command p_command, bool p_paused)
Playback process is being initialized. on_playback_new_track() should be called soon after this when ...
display_level_titles + timing + VBR bitrate display etc
void on_playback_dynamic_info_track(const file_info &p_info)
Per-track dynamic info (stream track titles etc) change. Happens less often than on_playback_dynamic_...
void on_playback_pause(bool p_state)
Called on pause/unpause.
Definition: play_callback.h:87
Main interface class for information about some playable object.
Definition: file_info.h:73
void on_volume_change(float p_new_val)
User changed volume settings. Possibly called when not playing.
Gets notified about tracks being played. Notification occurs when at least 60s of the track has been ...
virtual void on_playback_event()
void on_volume_change(float p_new_val)
User changed volume settings. Possibly called when not playing.
Definition: play_callback.h:92
Base class for all service classes. Provides interfaces for reference counter and querying for differ...
Definition: service.h:333
void play_callback_reregister(unsigned flags, bool refresh=false)
Definition: play_callback.h:78
Standard API (always present); manages registrations of dynamic play_callbacks. Usage: use static_api...
Definition: play_callback.h:54
void on_playback_stop(play_control::t_stop_reason p_reason)
Playback stopped.
t_display_level
Type used to indicate level of dynamic playback-related info displayed. Safe to use with <> opereator...
void on_playback_edited(metadb_handle_ptr p_track)
Called when currently played file gets edited.
Definition: play_callback.h:88
void on_playback_time(double p_time)
Called every second, for time display.
void on_playback_seek(double p_time)
User has seeked to specific time.
Definition: play_callback.h:86
Static (autoregistered) version of play_callback. Use play_callback_static_factory_t to register...
Definition: play_callback.h:98
void on_playback_new_track(metadb_handle_ptr p_track)
Playback advanced to new track.
Definition: play_callback.h:84
playback_event_notify(playback_control::t_display_level level=playback_control::display_level_all)
void on_playback_dynamic_info(const file_info &p_info)
Dynamic info (VBR bitrate etc) change.
Definition: play_callback.h:89
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition: service.h:533
void on_playback_pause(bool p_state)
Called on pause/unpause.
Helper providing a simplified interface for receiving playback events, in case your code does not car...
void on_playback_starting(play_control::t_track_command p_command, bool p_paused)
Playback process is being initialized. on_playback_new_track() should be called soon after this when ...
Definition: play_callback.h:83
void on_playback_stop(play_control::t_stop_reason p_reason)
Playback stopped.
Definition: play_callback.h:85
uint32_t t_uint32
Definition: int_types.h:5
void on_playback_edited(metadb_handle_ptr p_track)
Called when currently played file gets edited.
void on_playback_dynamic_info_track(const file_info &p_info)
Per-track dynamic info (stream track titles etc) change. Happens less often than on_playback_dynamic_...
Definition: play_callback.h:90