Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: callback for timecode? (Read 1984 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

callback for timecode?

Hello,
the callback virtual void FB2KAPI on_playback_time(double p_time) = 0; in play_callback.h
is every second. Is there also a callback every 10 or 100 Milliseconds? I want to build a Timecode output.

Günter

Re: callback for timecode?

Reply #1
The callback as you've noticed ticks at 1Hz and there is not any alternative to my knowledge.
In my foo_wave_seekbar component I poll the playback position on a WM_TIMER message as I draw at a particular rate anyway.
Code: [Select]
static_api_ptr_t<playback_control> pc;
double t = pc->playback_get_position();

It's worth noting that the times you get from the playback callback and the times you get from playback_get_position are not quite in sync, if you gather information from both you'll get hitches every second so I recommend only using one of the alternatives.
Stay sane, exile.

Re: callback for timecode?

Reply #2
Hello Zao,

thank you for your help!!!
Whats the lag of your Timer?

Edit: Is playback_get_position only in seconds???

Quote:
virtual double    playback_get_position ()=0
Returns current playback position within currently played track, in seconds.

I have installed your seekbar and it works fine. It is possible to start (or better pause) a stopped only by clicking on the waveform (set the cursor)?

Günter


Re: callback for timecode?

Reply #4
Hello marc2003,

thank for your help!
So i try to write a component which calls playback_get_position every 10 milliseconds and write the value to an serial Port.
2 decimal places are enough..

regards,
Günter

Re: callback for timecode?

Reply #5
Hello Zao,

how did you get access to the WMTimer?
I cant start the Timer...

Günter

Re: callback for timecode?

Reply #6
Hello,

the timer is running. But it has an Jitter when the song is played.

Code: [Select]
class myinitquit : public initquit {
public:
void on_init() {
console::print("Sample component: on_init()");
a.connect();
HWND w = core_api::get_main_window();
SetTimer(w, 12, 100, (TIMERPROC)&winproc);
}

Code: [Select]
static LRESULT CALLBACK winproc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
{

switch (msg)
{
case WM_TIMER:
if (wp == 12)
{
static_api_ptr_t<playback_control> pc;
unsigned long long t = abs(pc->playback_get_position()*10);
a.send(t);
}
break;

case WM_DESTROY:

return 0;
}

return uDefWindowProc(wnd, msg, wp, lp);
}

Re: callback for timecode?

Reply #7
Hello,

now i used the callback: virtual void FB2KAPI on_playback_time(double p_time) = 0;

This is also very unaccurate...
There is no callback at 0 Seconds.

Günter

Re: callback for timecode?

Reply #8
Wellcome to my Timeblog.

Code: [Select]
void on_playback_starting(play_control::t_track_command p_command, bool p_paused) {
ComPort.send(0);
}
void on_playback_time(double p_time) {
unsigned long long t = (unsigned long long)abs(p_time);
if (t == 1)ComPort.send(t);
}

The time between playback_starting and the first on_playback_time tick is between 1,2 and 1,4 Seconds. :o



Re: callback for timecode?

Reply #9
Time between release of the Playbutton (measured at the left Mouseswitch) , the on_playback_starting callback to an Comport is only 10-20 Milliseconds. :)

Re: callback for timecode?

Reply #10
Hello,

on_playback_starting
on_playback_time
on_playback_seek

works fine

on_playback_pause
on_playback_stop
on_volume_change

nothing happens

is something wrong with my code?

Code: [Select]
class play_callback_changes : public play_callback_static
{
void on_playback_new_track(metadb_handle_ptr p_track) {
}

void on_playback_stop(play_control::t_stop_reason p_reason) {
ComPort.send(1);//no event
}

void on_playback_dynamic_info_track(const file_info & p_info) {
}

void on_playback_edited(metadb_handle_ptr p_track) {
}

void on_playback_starting(play_control::t_track_command p_command, bool p_paused) {
ComPort.send(2);//OK
}
void on_playback_time(double p_time) {
//unsigned long long t = (unsigned long long)abs(p_time*100);
ComPort.send(3);//OK
}

void on_playback_seek(double p_time) {
ComPort.send(4);//OK
}

void on_playback_pause(bool p_state) {
ComPort.send(5);//no event
}

void on_playback_dynamic_info(const file_info & p_info) {
}

void on_volume_change(float p_new_val) {
ComPort.send(6);//no event
}

unsigned int get_flags() {
return flag_on_playback_new_track
| flag_on_playback_edited
| flag_on_playback_starting
| flag_on_playback_seek
| flag_on_playback_time
;
}
};

static play_callback_static_factory_t<play_callback_changes> g_play_callback_changes;

Re: callback for timecode?

Reply #11
Check your get_flags() ??

Re: callback for timecode?

Reply #12
yes, the flags will help!  :D

Re: callback for timecode?

Reply #13
So i will poll playback_get_position with a wm_timer all 10 ms to get the nearest startpoint of the soundfile. This startpoint go to an external mikrocontroller which generates the Miditimecode from an accurate clock, On_playback_pause and on_playback_stop will also set the external clock.

thanks for the help!
Günter