8000 Dev/mxs by aimxhaisse · Pull Request #12 · aimxhaisse/soir · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Dev/mxs #12

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

Merged
merged 2 commits into from
Dec 25, 2024
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
1 change: 1 addition & 0 deletions dist/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.tar.gz
*.lock
soir_engine
etc/config.yaml
121 changes: 71 additions & 50 deletions dist/bin/soir
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ _default:

# --- SETUP

# Show environment informations
# Show environment informations.
[group('setup')]
info:
setup-info:
#!/usr/bin/env bash
echo "SOIR_BASE_DIR: $SOIR_BASE_DIR"
echo "SOIR_DIR: $SOIR_DIR"
Expand All @@ -21,7 +21,7 @@ info:

# Check if dependencies are installed.
[group('setup')]
check-deps:
setup-check-deps:
#!/usr/bin/env bash
function check-dep {
if ! command -v $1 &> /dev/null; then
Expand All @@ -38,7 +38,7 @@ check-deps:

# Upgrade soir to the latest version.
[group('setup')]
upgrade:
setup-upgrade:
#!/usr/bin/env bash
curl -sL https://soir.dev/install.sh | bash

Expand All @@ -47,7 +47,7 @@ upgrade:
# Creates a new soir session.
[group('session')]
[no-cd]
new session:
session-new session:
#!/usr/bin/env bash

echo "Creating a new soir session {{ session }}"
Expand All @@ -67,7 +67,7 @@ new session:
# Runs a soir session.
[group('session')]
[no-cd]
run session:
session-run session:
#!/usr/bin/env bash

echo "Running soir session {{ session }}"
Expand All @@ -76,48 +76,11 @@ run session:

poetry -C ${SOIR_DIR} run -C ${SOIR_DIR} soir-engine --config etc/config.yaml

[private]
[no-cd]
prepare-config session template="config.yaml.template":
#!/usr/bin/env -S poetry -C {{ SOIR_DIR }} run python3.11
#
# Script to prepare the configuration file for a new soir session.
# It uses the template from the SOIR_DIR as a base.
import jinja2
import os
import sys

soir_dir = os.environ.get("SOIR_DIR")

def get_virtual_env_site_packages() -> str:
"""Returns the site-packages of the virtual environment.
"""
dirs = []
for path in sys.path:
if "site-packages" in path:
return path
raise ValueError("Could not find the site-packages directory")

def main(output: str) -> None:
with open(f"{soir_dir}/etc/{{ template }}", "r") as f:
template = jinja2.Template(f.read())
with open(f"{output}/etc/config.yaml", "w") as f:
f.write(
template.render(
soir_dir=os.environ.get("SOIR_DIR"),
audio_device_id=1,
site_packages=get_virtual_env_site_packages(),
)
)

if __name__ == '__main__':
main("{{session}}")

# --- SAMPLES

# List sample packs
# List sample packs.
[group('samples')]
sp-ls:
sample-ls-packs:
#!/usr/bin/env -S poetry -C {{ SOIR_DIR }} run python3.11
import os
import json
Expand Down Expand Up @@ -153,10 +116,10 @@ sp-ls:

main()

# Create a sample pack
# Create a sample pack.
[group('samples')]
[no-cd]
sp-mk sample-pack:
sample-mk-pack sample-pack:
#!/usr/bin/env -S poetry -C {{ SOIR_DIR }} run python3.11
import yaml
import os
Expand Down Expand Up @@ -202,15 +165,15 @@ sp-mk sample-pack:
with open(pack_file, "w") as f:
data = {'name': sp, 'samples': samples}
yaml.dump(data, f)
print(f"Sample pack { sp } created, you can now install it with `soir sp-install { sp }`")
print(f"Sample pack { sp } created, you can now install it with `soir sample-install-pack { sp }`")

main()


# Install a sample pack
# Install a sample pack.
[group('samples')]
[no-cd]
sp-install sample-pack:
sample-install-pack sample-pack:
#!/usr/bin/env bash

function check_if_installed {
Expand Down Expand Up @@ -245,3 +208,61 @@ sp-install sample-pack:
maybe_install_remote "{{ sample-pack }}"

echo "Sample pack ${1} not found"


# Convert a sample directory to 48kHz.
[group('samples')]
[no-cd]
sample-convert-48khz sample-dir:
#!/usr/bin/env bash

function convert {
if [ -f "${1}/${2}" ]; then
ffmpeg -i "${1}/${2}" -ar 48000 -ac 2 "${1}/${2}.48khz.wav"
rm "${1}/${2}"
mv "${1}/${2}.48khz.wav" "${1}/${2}"
fi
}

for file in $(find "{{ sample-dir }}" -type f -name "*.wav"); do
convert $(dirname "${file}") $(basename "${file}")
done


# --- HELPERS

[private]
[no-cd]
prepare-config session template="config.yaml.template":
#!/usr/bin/env -S poetry -C {{ SOIR_DIR }} run python3.11
#
# Script to prepare the configuration file for a new soir session.
# It uses the template from the SOIR_DIR as a base.
import jinja2
import os
import sys

soir_dir = os.environ.get("SOIR_DIR")

def get_virtual_env_site_packages() -> str:
"""Returns the site-packages of the virtual environment.
"""
dirs = []
for path in sys.path:
if "site-packages" in path:
return path
raise ValueError("Could not find the site-packages directory")

def main(output: str) -> None:
with open(f"{soir_dir}/etc/{{ template }}", "r") as f:
template = jinja2.Template(f.read())
with open(f"{output}/etc/config.yaml", "w") as f:
f.write(
template.render(
soir_dir=os.environ.get("SOIR_DIR"),
audio_device_id=1,
site_packages=get_virtual_env_site_packages(),
)
)

main("{{session}}")
2 changes: 1 addition & 1 deletion dist/etc/config.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ soir:
host: localhost
port: 9430
dsp:
sample_directory: ./samples
sample_directory: {{ soir_dir }}/samples
output:
audio:
enable: true
Expand Down
2 changes: 1 addition & 1 deletion dist/etc/scripts.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ soir:
host: localhost
port: 9000
dsp:
sample_directory: assets/samples
sample_directory: {{ soir_dir }}/samples
output:
audio:
# Disable audio so that we can generate documentation without
Expand Down
37 changes: 31 additions & 6 deletions dist/install.sh → install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,56 @@ BASE_DIR="${XDG_CONFIG_HOME:-$HOME}"
SOIR_DIR="${SOIR_DIR:-"$BASE_DIR/.soir"}"
SOIR_BIN_DIR="$SOIR_DIR/bin"

function get_arch {
case $(uname -m) in
arm64)
echo "aarch64"
;;
*)
echo "soir: architecture not supported."
exit 1
;;
esac
}

function get_os {
case $(uname -s) in
Darwin)
echo "macos"
;;
*)
echo "soir: operating system not supported."
exit 1
;;
esac
}

TAG=$(curl -s "https://api.github.com/repos/aimxhaisse/soir/releases/latest" | jq -r .tag_name)
RELEASE="soir-${TAG}-{{ arch() }}-{{ os() }}"
RELEASE="soir-${TAG}-$(get_arch)-$(get_os)"

function install_deps {
if [[ "$OSTYPE" =~ ^darwin ]]; then
if ! command -v brew &> /dev/null; then
echo "soir: homebrew is required to install dependencies."
exit 1
fi
brew install --quiet just jq python@3.11 poetry curl
brew install --quiet just jq python@3.11 poetry curl ffmpeg
fi
}

function install_dist {
echo "Setting up distribution for ${TAG}"
mkdir -p ${SOIR_DIR}
cd "${SOIR_DIR}"
curl -s "https://github.com/aimxhaisse/soir/archive/refs/tags/${TAG}.tar.gz" -o "${SOIR_DIR}/soir-${TAG}.tar.gz"
curl -Ls "https://github.com/aimxhaisse/soir/releases/download/${TAG}/${RELEASE}.tar.gz" -o "${SOIR_DIR}/soir-${TAG}.tar.gz"
tar -xzf "${SOIR_DIR}/soir-${TAG}.tar.gz" --strip-components=1 -C "${SOIR_DIR}"
rm -f "${SOIR_DIR}/soir-${TAG}.tar.gz"
}

function install_py {
echo "Setting up Python dependencies for ${TAG}"
poetry -C ${SOIR_DIR} env use -C ${SOIR_DIR} python3.11 -q
poetry -C ${SOIR_DIR} install -C ${SOIR_DIR} -q
poetry -C ${SOIR_DIR} env use -C ${SOIR_DIR} python3.11
poetry -C ${SOIR_DIR} install -C ${SOIR_DIR}
}

function install_path {
Expand Down Expand Up @@ -72,4 +97,4 @@ install_dist
install_py
install_path

echo "soir was installed successfully to ${SOIR_BIN_DIR}"
echo "soir was installed successfully to ${SOIR_BIN_DIR}, please restart your shell to apply changes."
31 changes: 18 additions & 13 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import 'dist/bin/soir'
_default:
@just --list --unsorted --justfile {{ justfile() }}


# Build Soir.
[group('dev')]
build:
dev-build:
#!/usr/bin/env bash
if ! [ -f build ]
then
Expand All @@ -24,34 +25,38 @@ build:

# Runs the Soir unit test suites.
[group('dev')]
test filter='*':
dev-test filter='*':
#!/usr/bin/env bash
tmp=$(mktemp -d)
mkdir -p "${tmp}/etc"
just --justfile {{ justfile() }} prepare-config ${SOIR_DIR} ${tmp} "scripts.yaml.template"
just --justfile {{ justfile() }} prepare-config dist "scripts.yaml.template"
poetry -C ${SOIR_DIR} run make test TEST_FILTER={{filter}}
rm -rf ${tmp}

# Build and push documentation to soir.sbrk.org.
# Build and push documentation to soir.dev.
[group('dev')]
mkdocs:
dev-mk-docs:
#!/usr/bin/env bash
tmp=$(mktemp -d)
mkdir -p "${tmp}/etc"
just --justfile {{ justfile() }} prepare-config ${SOIR_DIR} ${tmp} "scripts.yaml.template"
poetry -C ${SOIR_DIR} run -C ${SOIR_DIR} ${SOIR_BIN_DIR}/soir-engine --config "${tmp}/etc/config.yaml" --mode script --script scripts/mk-docs.py
rm -rf ${tmp}
cp dist/install.sh www/site/
just --justfile {{ justfile() }} prepare-config dist "scripts.yaml.template"
poetry -C ${SOIR_DIR} run -C ${SOIR_DIR} ${SOIR_BIN_DIR}/soir-engine --config dist/etc/config.yaml --mode script --script scripts/mk-docs.py
cp install.sh www/site/

# Run the Soir engine in audio mode.
[group('dev')]
dev-run:
#!/usr/bin/env bash
just --justfile {{ justfile() }} prepare-config dist "config.yaml.template"
poetry -C ${SOIR_DIR} run -C ${SOIR_DIR} ${SOIR_BIN_DIR}/soir-engine --config dist/etc/config.yaml --mode standalone

# Push the documentation to soir.sh.
[group('dev')]
push-docs: mkdocs
dev-sync-docs: dev-mk-docs
#!/usr/bin/env bash
rsync -avz --delete www/site/ soir.dev:services/soir.dev/data

# Build the package for Soir.
[group('dev')]
package: build
dev-mk-package: dev-build
#!/usr/bin/env bash
git fetch --tags
TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
Expand Down
7 changes: 4 additions & 3 deletions src/core/dsp/sample_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ absl::Status SampleManager::Init(const utils::Config& config) {

if (absl::EndsWith(candidate_pack, ".pack.yaml")) {
auto pack = candidate_pack.substr(0, candidate_pack.size() - 10);
LOG(INFO) << "Loading pack: " << pack;

auto status = LoadPack(pack);
if (!status.ok()) {
return status;
Expand All @@ -41,6 +39,8 @@ absl::Status SampleManager::Init(const utils::Config& config) {
absl::Status SampleManager::LoadPack(const std::string& name) {
auto config_path = directory_ + "/" + name + ".pack.yaml";

LOG(INFO) << "Loading pack: " << name;

{
std::lock_guard<std::mutex> lock(mutex_);
if (packs_.find(name) != packs_.end()) {
Expand All @@ -50,8 +50,9 @@ absl::Status SampleManager::LoadPack(const std::string& name) {

SamplePack pack;

auto status = pack.Init(config_path);
auto status = pack.Init(directory_, config_path);
if (!status.ok()) {
LOG(ERROR) << "Failed to load pack " << name << ": " << status;
return status;
}

Expand Down
Loading
0