Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some config options #35

Merged
merged 6 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@ name: Build sys-tune and overlay
on: [push]
jobs:
build:

runs-on: ubuntu-latest
container: devkitpro/devkita64
container: devkitpro/devkita64:latest

steps:
- uses: actions/checkout@v1
- name: Checkout
uses: actions/checkout@master
with:
submodules: recursive

- name: Building libnx-Ext
- name: Build
run: |
make -j$(nproc) -C sys-tune/nxExt
make -j$(nproc)
mkdir -p dist/switch/.overlays
mkdir -p dist/atmosphere/contents/4200000000000000/flags
touch dist/atmosphere/contents/4200000000000000/flags/boot2.flag
cp sys-tune/sys-tune.nsp dist/atmosphere/contents/4200000000000000/exefs.nsp
cp sys-tune/toolbox.json dist/atmosphere/contents/4200000000000000/
cp overlay/sys-tune-overlay.ovl dist/switch/.overlays/

- name: Building sys-tune
run: |
API_VERSION=9 make -j$(nproc)
- uses: actions/upload-artifact@master
with:
name: sys-tune
path: dist
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*.nacp
*.npdm
*.ovl
.vscode
.vscode/settings.json
build
dist
*.zip
22 changes: 22 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"configurations": [
{
"name": "switch",
"includePath": [
"${default}",
"${workspaceFolder}/**",
"${DEVKITPRO}/libnx/include/",
"${DEVKITPRO}/portlibs/switch/include/",
"${workspaceFolder}/sys-tune/nxExt/include/",
"${workspaceFolder}/overlay/lib/include/",
"${workspaceFolder}/ipc/",
"${workspaceFolder}/common/"
],
"defines": ["__SWITCH__", "WANT_MP3", "WANT_FLAC", "WANT_WAV"],
"cStandard": "gnu17",
"cppStandard": "gnu++23",
"compilerPath": "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc"
}
],
"version": 4
}
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export GITHASH := $(shell git rev-parse --short HEAD)
export VERSION := 1.2.2
export API_VERSION := 3
export VERSION := 2.0.0
export API_VERSION := 4
export WANT_FLAC := 1
export WANT_MP3 := 1
export WANT_WAV := 1
Expand All @@ -11,8 +11,8 @@ clean:
$(MAKE) -C sys-tune/nxExt clean
$(MAKE) -C overlay clean
$(MAKE) -C sys-tune clean
rm -rf dist
rm sys-tune-*-*.zip
-rm -r dist
-rm sys-tune-*-*.zip

overlay:
$(MAKE) -C overlay
Expand All @@ -28,7 +28,8 @@ dist: all
mkdir -p dist/atmosphere/contents/4200000000000000
cp sys-tune/sys-tune.nsp dist/atmosphere/contents/4200000000000000/exefs.nsp
cp overlay/sys-tune-overlay.ovl dist/switch/.overlays/
cp sys-tune/toolbox.json dist/atmosphere/contents/4200000000000000/
cd dist; zip -r sys-tune-$(VERSION)-$(GITHASH).zip ./**/; cd ../;
hactool -t nso sys-tune/sys-tune.nso
-hactool -t nso sys-tune/sys-tune.nso

.PHONY: all overlay module
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ You can manage playback via the Tesla overlay in the release.
## Special thanks to:
- [mackron](http://mackron.github.io/) who made the awesome [audio decoders used here.](https://github.com/mackron/dr_libs/)
- [WerWolv](https://werwolv.net/) for making libtesla, the UI library used for the control overlay.
- [TotalJustice](https://github.com/ITotalJustice) for bug fixes, adding some features and bad code.

## Info for developers
I implemented an IPC interface accessible via service wrappers [here](/ipc/).
Expand Down
114 changes: 114 additions & 0 deletions common/config/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include "config.hpp"
#include "sdmc/sdmc.hpp"
#include "minIni/minIni.h"
#include <cstdio>

namespace config {

namespace {

const char CONFIG_PATH[]{"/config/sys-tune/config.ini"};
// blacklist uses it's own config file because eventually a database
// may be setup and users can easily update their blacklist by downloading
// an updated blacklist.ini.
// Also, the blacklist lookup needs to be as fast as possible
// (literally a race until the title opens audren), so a seperate, smaller file is ideal.
const char BLACKLIST_PATH[]{"/config/sys-tune/blacklist.ini"};

void create_config_dir() {
/* Creating directory on every set call looks sus, but the user may delete the dir */
/* whilst the sys-mod is running and then any changes made via the overlay */
/* is lost, which sucks. */
sdmc::CreateFolder("/config");
sdmc::CreateFolder("/config/sys-tune");
}

auto get_tid_str(u64 tid) -> const char* {
static char buf[21]{};
std::sprintf(buf, "%016lX", tid);
return buf;
}

}

auto get_shuffle() -> bool {
return ini_getbool("config", "shuffle", false, CONFIG_PATH);
}

void set_shuffle(bool value) {
create_config_dir();
ini_putl("config", "shuffle", value, CONFIG_PATH);
}

auto get_repeat() -> int {
return ini_getl("config", "repeat", 1, CONFIG_PATH);
}

void set_repeat(int value) {
create_config_dir();
ini_putl("config", "repeat", value, CONFIG_PATH);
}

auto get_volume() -> float {
return ini_getf("config", "volume", 1.f, CONFIG_PATH);
}

void set_volume(float value) {
create_config_dir();
ini_putf("config", "volume", value, CONFIG_PATH);
}

auto has_title_enabled(u64 tid) -> bool {
return ini_haskey("title", get_tid_str(tid), CONFIG_PATH);
}

auto get_title_enabled(u64 tid) -> bool {
return ini_getbool("title", get_tid_str(tid), true, CONFIG_PATH);
}

void set_title_enabled(u64 tid, bool value) {
create_config_dir();
ini_putl("title", get_tid_str(tid), value, CONFIG_PATH);
}

auto get_title_enabled_default() -> bool {
return ini_getbool("title", "default", true, CONFIG_PATH);
}

void set_title_enabled_default(bool value) {
create_config_dir();
ini_putl("title", "default", value, CONFIG_PATH);
}

auto has_title_volume(u64 tid) -> bool {
return ini_haskey("volume", get_tid_str(tid), CONFIG_PATH);
}

auto get_title_volume(u64 tid) -> float {
return ini_getf("volume", get_tid_str(tid), 1.f, CONFIG_PATH);
}

void set_title_volume(u64 tid, float value) {
create_config_dir();
ini_putf("volume", get_tid_str(tid), value, CONFIG_PATH);
}

auto get_default_title_volume() -> float {
return ini_getf("config", "global_volume", 1.f, CONFIG_PATH);
}

void set_default_title_volume(float value) {
create_config_dir();
ini_putf("config", "global_volume", value, CONFIG_PATH);
}

auto get_title_blacklist(u64 tid) -> bool {
return ini_getbool("blacklist", get_tid_str(tid), false, BLACKLIST_PATH);
}

void set_title_blacklist(u64 tid, bool value) {
create_config_dir();
ini_putl("blacklist", get_tid_str(tid), value, BLACKLIST_PATH);
}

}
41 changes: 41 additions & 0 deletions common/config/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include <switch.h>

namespace config {

// tune shuffle
auto get_shuffle() -> bool;
void set_shuffle(bool value);

// tune repeat
auto get_repeat() -> int;
void set_repeat(int value);

// tune volume
auto get_volume() -> float;
void set_volume(float value);

// per title tune enable
auto has_title_enabled(u64 tid) -> bool;
auto get_title_enabled(u64 tid) -> bool;
void set_title_enabled(u64 tid, bool value);

// default for tune for every title
auto get_title_enabled_default() -> bool;
void set_title_enabled_default(bool value);

// per title volume
auto has_title_volume(u64 tid) -> bool;
auto get_title_volume(u64 tid) -> float;
void set_title_volume(u64 tid, float value);

// default volume for every title
auto get_default_title_volume() -> float;
void set_default_title_volume(float value);

// returns true if title causes a fatal on launch
auto get_title_blacklist(u64 tid) -> bool;
void set_title_blacklist(u64 tid, bool value);

}
Loading