HookedBehemoth / sys-tune

Background audio player for the Nintendo switch
145 stars 10 forks source link

add some config options #35

Closed ITotalJustice closed 10 months ago

ITotalJustice commented 1 year ago

Not sure if you want to merge this, i didn't really follow your coding style. i can update it so that it does, if this is something you would like merged.

more config options can be added at a later date, such as button combo to change songs without having to use the overlay, change default music path, auto load music path on load, option to save playlists, option to load playlists.


the config options aren't checked for validity btw, i forgot to do that. this could be especially bad for volume. i'll have some more time again in a few days


i have noticed a fatal happens when closing sys-tune using the overlay. this doesn't happen in your latest release, but does if i build https://github.com/HookedBehemoth/sys-tune/commit/512e2740a5bf0cd9df2f6a4da538c8e18f0003b3 from source. have you noticed this on your end? i am using latest everything in dkp.

ITotalJustice commented 1 year ago

this would also fix #22, #19 and #33.

HookedBehemoth commented 1 year ago

Thanks for this all. The code style is fine, especially because my own taste refined since I wrote this.

Did you have issues with -O3 or did you not find any improvements? Also I don't believe this needs a reboot. Getting killed by another process might suck though.

I'll try to look at it more closely and merge this either this evening or tomorrow.

ITotalJustice commented 1 year ago

i changed O3 to O2 because the binary size was slightly smaller 396.1 KiB (405,560) vs 416.1 KiB (426,040).

sys-tune fails to be started again after being forcefully closed. haven't checked as to why yet.


do you know how to manage a process volume output? I see audout:a had SetProcessMasterVolume but it was removed in 11.0.0.

HookedBehemoth commented 1 year ago

might need to call svcManageNamedPort with max_sessions = 0 to force the kernel to close the old port.

HookedBehemoth commented 1 year ago

I remember wasting a lot of time on trying to get audio controls for other processes working before. I sadly don't remember a lot and I haven't noted anything down either. audout:a moved to aud:a. Maybe that's off use? https://switchbrew.org/wiki/Audio_services#aud:a

Mary from Ryujinx knows a lot about the Audio. Could bug him about it.

ITotalJustice commented 1 year ago

I remember wasting a lot of time on trying to get audio controls for other processes working before. I sadly don't remember a lot and I haven't noted anything down either. audout:a moved to aud:a. Maybe that's off use? https://switchbrew.org/wiki/Audio_services#aud:a

Mary from Ryujinx knows a lot about the Audio. Could bug him about it.

aud:a looks good, thank you. i'll mess around after work or tomorrow. Otherwise yeah i'll ping Mary.

ITotalJustice commented 1 year ago

instead of displaying the tid of the current application, do you think it should display it's name instead? i added some code for this:

    auto control_data = std::make_unique<NsApplicationControlData>();
    u64 control_data_size{};
    std::string tid_name;

    if (tid == 0x0100000000001000ULL) {
        tid_name = "qlaunch";
    } else if (R_SUCCEEDED(nsGetApplicationControlData(NsApplicationControlSource_Storage, tid, control_data.get(), sizeof(NsApplicationControlData), &control_data_size))) {
        tid_name = control_data->nacp.lang[0].name;
    } else {
        char id_buf[21]{};
        std::sprintf(id_buf, "%016lx", tid);
        tid_name = id_buf;
    }

this works fine. then i thought about displaying the game icon, seeing as i already fetch the entire nacp

    auto control_data = std::make_unique<NsApplicationControlData>();
    u64 control_data_size{};
    std::string tid_name;

    if (tid == 0x0100000000001000ULL) {
        tid_name = "qlaunch";
    } else if (R_SUCCEEDED(nsGetApplicationControlData(NsApplicationControlSource_Storage, tid, control_data.get(), sizeof(NsApplicationControlData), &control_data_size))) {
        tid_name = control_data->nacp.lang[0].name;
        const CapsScreenShotDecodeOption option{};
        std::vector<u8> image_bitmap(256*256*4);
        tsl::hlp::doWithSmSession(capsdcInitialize);
        if (R_SUCCEEDED(capsdcDecodeJpeg(256, 256, &option, control_data->icon, control_data_size - sizeof(NacpStruct), image_bitmap.data(), image_bitmap.size()))) {
            list->addItem(new ElmIcon(std::move(image_bitmap)));
        }
        capsdcExit();
    } else {
        char id_buf[21]{};
        std::sprintf(id_buf, "%016lx", tid);
        tid_name = id_buf;
    }

i don't yet scale down the icon, and i'm not sure its worth displaying tbh. if you did want this, would you want it to be the left side of the title_name?

2023061311220600-57B4628D2267231D57E0FC1078C0596D 2023061312161600-DECD6107E5477CFA2919C447E5B68FF0 2023061312220700-DECD6107E5477CFA2919C447E5B68FF0 2023061312222800-57B4628D2267231D57E0FC1078C0596D

HookedBehemoth commented 1 year ago

lol I forgot that you could use jpegdec for that too

HookedBehemoth commented 1 year ago

This used to have the boot2.flag but I decided to remove it because of the aborts with some games. See https://github.com/HookedBehemoth/sys-tune/issues/10 Currently I expect users to start and stop it with the overlay.

Maybe the pmdmnt loop could be used to check against these titles and shut down the audio thread. Otherwise I fear a lot of issues will rain in again.

ITotalJustice commented 1 year ago

Ah okay. Well the stopping the sys-mod using the overlay fatals for me (only if built from source...), not sure how to fix that tbh.

I'll try force closing sys-tune when a title in a blacklist is launched. Hopefully that title is detected before the title opens the audio services that causes the fatal.

HookedBehemoth commented 1 year ago

Did you try to diagnose the issue? Is sys-tune itself crashing? Does it happen on master? Maybe using pgl instead of pmdmnt helps but that requires 10.0.0+ (not sure how low it currently goes)

ITotalJustice commented 1 year ago

No I didn't try and diagnose it. It does happen on master and also tried https://github.com/HookedBehemoth/sys-tune/commit/512e2740a5bf0cd9df2f6a4da538c8e18f0003b3 which I believe is what you built your last release from. This doesn't happen using your latest release however so who knows, could be libnx or gcc change :/

And yes its sys_tune that causes the fatal

monstrosities commented 1 year ago

No I didn't try and diagnose it. It does happen on master and also tried 512e274 which I believe is what you built your last release from. This doesn't happen using your latest release however so who knows, could be libnx or gcc change :/

And yes its sys_tune that causes the fatal

I have the exact same issue with TriPlayer which is another audio player sysmodule: stopping the sysmodule from the overlay works fine with an older version I compiled but when I recompiled it last month it will now crash atmosphere when stopping the sysmodule from its overlay. My older version that doesn't crash is only a few months old so this has to be down to a recent compiler/library change.

ITotalJustice commented 1 year ago

i think i'm finished with everything now.

somewhat fixes #10 and #31 as well

amitkulk123 commented 10 months ago

Any update to this PR and if it's getting merged? I've been running it on my Switch and it works great and autoplays the music whenever I close an app/game or wake it from sleep. I noticed it doesn't pause the music when I resume the app/game though so I have to manually pause it through the menu. But it works well aside from that.

ITotalJustice commented 10 months ago

Any update to this PR and if it's getting merged? I've been running it on my Switch and it works great and autoplays the music whenever I close an app/game or wake it from sleep. I noticed it doesn't pause the music when I resume the app/game though so I have to manually pause it through the menu. But it works well aside from that.

Sorry, I forgot about this pr. I have no free time anymore so I likely won't get around to working on this again.

As for the pausing, there should be an option in the menu to set a global default for all apps (including the home menu). If you set that to paused, then the music will be paused by default when you first launch any app. You can then change the config per game.

In your case, I think you'd want to set the global default to pause, then make the home menu play music. If this doesn't work then let me know. I won't be at my pc to fix stuff but I can still read code on my breaks 😄

carr654 commented 10 months ago

Any update to this PR and if it's getting merged? I've been running it on my Switch and it works great and autoplays the music whenever I close an app/game or wake it from sleep. I noticed it doesn't pause the music when I resume the app/game though so I have to manually pause it through the menu. But it works well aside from that.

as an average user how would i go about using this as i was the one who put the request in with many and still looking forward to it. its a shame ijustice has no time now. just dont want this project to not have an outcome as it really would make the modding scene happy

amitkulk123 commented 10 months ago

Any update to this PR and if it's getting merged? I've been running it on my Switch and it works great and autoplays the music whenever I close an app/game or wake it from sleep. I noticed it doesn't pause the music when I resume the app/game though so I have to manually pause it through the menu. But it works well aside from that.

as an average user how would i go about using this as i was the one who put the request in with many and still looking forward to it. its a shame ijustice has no time now. just dont want this project to not have an outcome as it really would make the modding scene happy

Same this is one of my most wanted features too because the Switch menu feels so odd without some music since I'm used to the Wii and 3DS menus.

So if you want to get the latest build from ITotalJustice, you can go here: https://github.com/ITotalJustice/sys-tune/actions and then click on the latest commit. From there, just download the sys-tune file under Artifacts and then put it on your Switch.

carr654 commented 10 months ago

Any update to this PR and if it's getting merged? I've been running it on my Switch and it works great and autoplays the music whenever I close an app/game or wake it from sleep. I noticed it doesn't pause the music when I resume the app/game though so I have to manually pause it through the menu. But it works well aside from that.

as an average user how would i go about using this as i was the one who put the request in with many and still looking forward to it. its a shame ijustice has no time now. just dont want this project to not have an outcome as it really would make the modding scene happy

Same this is one of my most wanted features too because the Switch menu feels so odd without some music since I'm used to the Wii and 3DS menus.

So if you want to get the latest build from ITotalJustice, you can go here: https://github.com/ITotalJustice/sys-tune/actions and then click on the latest commit. From there, just download the sys-tune file under Artifacts and then put it on your Switch.

awesome thank you, how do i go about assigning music to the home menu or is it pretty self explanatory once i got it on my switch

amitkulk123 commented 10 months ago

Any update to this PR and if it's getting merged? I've been running it on my Switch and it works great and autoplays the music whenever I close an app/game or wake it from sleep. I noticed it doesn't pause the music when I resume the app/game though so I have to manually pause it through the menu. But it works well aside from that.

as an average user how would i go about using this as i was the one who put the request in with many and still looking forward to it. its a shame ijustice has no time now. just dont want this project to not have an outcome as it really would make the modding scene happy

Same this is one of my most wanted features too because the Switch menu feels so odd without some music since I'm used to the Wii and 3DS menus. So if you want to get the latest build from ITotalJustice, you can go here: https://github.com/ITotalJustice/sys-tune/actions and then click on the latest commit. From there, just download the sys-tune file under Artifacts and then put it on your Switch.

awesome thank you, how do i go about assigning music to the home menu or is it pretty self explanatory once i got it on my switch

So you just need to put all your music on the /music on your sd card and then you can add it to your playlist and play it by opening the tesla menu

carr654 commented 10 months ago

So you just need to put all your music on the /music on your sd card and then you can add it to your playlist and play it by opening the tesla menu

okay thank you. just done that but it plays during game which i dont want it to. im guessing thats because its not a finished build. or i might be missing something to assign it just to the home menu.

edit: nvm i did it yay hello menu music

amitkulk123 commented 10 months ago

So you just need to put all your music on the /music on your sd card and then you can add it to your playlist and play it by opening the tesla menu

okay thank you. just done that but it plays during game which i dont want it to. im guessing thats because its not a finished build. or i might be missing something to assign it just to the home menu.

Same thing happens for me. I just manually pause when in-game. I’ll try to see if I can fix it so that it pauses when in-game but I’m not that experienced with this stuff.

carr654 commented 10 months ago

Same thing happens for me. I just manually pause when in-game. I’ll try to see if I can fix it so that it pauses when in-game but I’m not that experienced with this stuff.

i did what i justice said turn default to tune default to pause. and it pauses th music. im messing with the sounds now to get the song length correct

ITotalJustice commented 10 months ago

Any update to this PR and if it's getting merged? I've been running it on my Switch and it works great and autoplays the music whenever I close an app/game or wake it from sleep. I noticed it doesn't pause the music when I resume the app/game though so I have to manually pause it through the menu. But it works well aside from that.

Sorry, I forgot about this pr. I have no free time anymore so I likely won't get around to working on this again.

As for the pausing, there should be an option in the menu to set a global default for all apps (including the home menu). If you set that to paused, then the music will be paused by default when you first launch any app. You can then change the config per game.

In your case, I think you'd want to set the global default to pause, then make the home menu play music. If this doesn't work then let me know. I won't be at my pc to fix stuff but I can still read code on my breaks 😄

Please follow the steps here to have it so that it doesn't play music by default. Then you can enable music on a per title basis, including the home menu

carr654 commented 10 months ago

Please follow the steps here to have it so that it doesn't play music by default. Then you can enable music on a per title basis, including the home menu

sorry to bother you and i know this is not technically a release and your not working on it now. how would i go about it always being sucessful for menu music for example i have the zelda song thats 2 mins ish. once i first play the song and then enter a game it stops which is good. but when its near the middle of the song it doesnt do that. would i just have to trim down the song and put it on loop if i can? for it to always be successful in stopping when in game

edit: again nvm it just needs time to recognise. thank you for just getting a temp one done to experiment with its works good :)

HookedBehemoth commented 10 months ago

Thank you very much <3

HookedBehemoth commented 10 months ago

Was there a blacklist.ini you had prepared so I can throw that into a release?

ITotalJustice commented 10 months ago

Was there a blacklist.ini you had prepared so I can throw that into a release?

No, I embedded the games TID into the app itself https://github.com/HookedBehemoth/sys-tune/blob/702cdd01720c65a4230c30665df351fba56832b2/sys-tune/source/impl/music_player.cpp#L235 though maybe I should've added that list to the ini.

Iirc I was worried about the ini not being read fast enough before the fatal would occur, so I first tested using a lut. I'm pretty sure I did test reading from an ini file and it was fine