Skip to main content

Topic: How to force the calling order ? (Read 2078 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • lowzoom
  • [*]
How to force the calling order ?
I have a function:

Code: [Select]
void func(){
    // initialization ignored ...

    static_api_ptr_t<play_control>()->start(play_control::track_command_next);
    static_api_ptr_t<playlist_manager> ()->playlist_remove_items(list_idx, bit_array_one(item_idx));
}

When the function is called, foobar2k always removes the song before playing the next one.
This would lead to the "wrong" next song to be played.


I also tried a callback on starting, which, however, makes foobar2k crash...

Code: [Select]
// in a class named RemoveCallBack:
void on_playback_starting(play_control::t_track_command p_command,bool p_paused) {
    static_api_ptr_t<playlist_manager> list;
    list->playlist_remove_items(list_idx, bit_array_one(item_idx));
    static_api_ptr_t<play_callback_manager>()->unregister_callback(this);
}

// the previous func
void func(){
    // initialization ignored ...

    static_api_ptr_t<play_callback_manager>()->register_callback(
        new service_impl_t<RemoveCallBack>,
        play_callback::flag_on_playback_starting,
        false
    );
    static_api_ptr_t<play_control>()->start(play_control::track_command_next);
}

How can I force foobar2k to play the next song before removing a specific song from the playlist?

Thanks.
  • Last Edit: 04 November, 2011, 01:28:26 PM by db1989

  • Zao
  • [*][*][*][*][*]
  • Developer (Donating)
How to force the calling order ?
Reply #1
Verify in the SDK comments whether it's legal to modify the playlist while in a play callback.
If it's forbidden, which it probably is, you can register a main_thread_callback from there, and do your operation inside of that.

In particular, it may be illegal to unregister a callback from inside itself. Yet another case where a main_thread_callback helps.
  • Last Edit: 02 November, 2011, 07:25:54 AM by Zao
Zao shang yong zao nong zao rang zao ren zao.
To, early in the morning, use a chisel to build a bathtub makes impatient people hot-tempered.

  • lowzoom
  • [*]
How to force the calling order ?
Reply #2
Verify in the SDK comments whether it's legal to modify the playlist while in a play callback.
If it's forbidden, which it probably is, you can register a main_thread_callback from there, and do your operation inside of that.

In particular, it may be illegal to unregister a callback from inside itself. Yet another case where a main_thread_callback helps.

Yes, you're right. It's the unregister-self behavior that crashes foobar2k.

I've followed your advice and unregistered the callback successfully.
But... foobar2k still removes the song before starting to play the next one,
which is opposite to my expectation and causes the "wrong" next song to play.
That really confuses me.

Is there any other way to get the thing done:
Start playing the next song in the current playing order first, and then remove the previous one from the playlist ?

Thank you.

  • foosion
  • [*][*][*][*][*]
  • Moderator
How to force the calling order ?
Reply #3
Playlist modifications happen synchronously, whereas the playback start request is processed asynchronously. One way to achieve the desired result might be to use the playback queue. You could add the track to the queue using its playlist position, start playback and remove the song from the playlist. Of course you would also have to worry about the state of the playback queue, i.e. whether it is empty. I think that is how I handled it in foo_utils.
http://foosion.foobar2000.org/ - my components for foobar2000

  • lowzoom
  • [*]
How to force the calling order ?
Reply #4
Playlist modifications happen synchronously, whereas the playback start request is processed asynchronously. One way to achieve the desired result might be to use the playback queue. You could add the track to the queue using its playlist position, start playback and remove the song from the playlist. Of course you would also have to worry about the state of the playback queue, i.e. whether it is empty. I think that is how I handled it in foo_utils.

Very impressive... You know really a lot! Are you the author of foobar2k?

Your method works very good, however, except one thing:
It seems that I have to decide the next song myself.

Any way to know which song is the next to play in the current playing order (without actually playing it) ?

Thank you.
  • Last Edit: 02 November, 2011, 11:45:09 AM by lowzoom

  • mudlord
  • [*][*][*][*][*]
  • Developer (Donating)
How to force the calling order ?
Reply #5
Very impressive... You know really a lot! Are you the author of foobar2k?


No, foosion worked on some portions of the player. Another person did the rest, etc...

  • lowzoom
  • [*]
How to force the calling order ?
Reply #6
Very impressive... You know really a lot! Are you the author of foobar2k?


No, foosion worked on some portions of the player. Another person did the rest, etc...

So maybe I should call him one of the authors ?

  • db1989
  • [*][*][*][*][*]
  • Global Moderator
How to force the calling order ?
Reply #7
foosion contributed to foobar2000 itself between 2005 and 2006, but has been more active in creating various components for it and maintaining the tutorials for others interested in doing so; hence, no doubt, his knowledge of its inner workings.

  • foosion
  • [*][*][*][*][*]
  • Moderator
How to force the calling order ?
Reply #8
Yeah, what the others said. I have been around since about 2002 as a foobar2000 user, plugin author, forum moderator and alpha tester. I have contributed some parts to foobar2000 and the SDK, and was sometimes mistaken for being its author. ;-) My most active time was until 2006/2007. Since then life, work and other interests have taken their toll on the time I spend on foobar2000 and my knowledge of the SDK is getting hazy. I still try to help new developers to get started with the SDK which has become significantly more complex in the past nine years.

Hm, I think I should put this text on my profile page here on the forum. :-)
http://foosion.foobar2000.org/ - my components for foobar2000