Skip to main content

Add your description here

Project description

songtools

A Python DSL for composing music from code. Notes carry expression, structure carries time. No magic strings, no duplicate logic or state.

Install

uv add songtools

Requires Python 3.14+ and sounddevice (PortAudio backend).

Core idea

The library revolves around the Sound object. Use the @ operator to transform sounds:

  • sound @ Effect: Applies a DSP effect.
  • sound @ Key: Applies a harmonic context.
  • sound @ Degree: Applies a relative pitch shift based on a key.

Abstractions

Name What it is
Sound The primary object. Contains samples and harmonic context.
Buffer Low-level wrapper around a float array for audio data.
Key Harmonic context: root + scale + quality.
WavFile Utility for reading/writing 16-bit PCM WAV files.

Operators

Op Meaning
a + b Concatenation (a, then b)
a * n Repetition (repeat a, n times)
a & b Mixing (linear sum of buffers)
a @ transform Transform (Effect, Key, or Degree)

Vocabulary

  • Notes/Degrees: Degree.I through Degree.VII.
  • Scales: Scale.MAJOR, Scale.MINOR, Scale.DORIAN.
  • Qualities: Quality.TRIAD, Quality.SEVENTH, Quality.NINTH, Quality.SUS2, Quality.SUS4, Quality.POWER.
  • Roots: KeyRoot.C, KeyRoot.CS, etc.

Effects

Chain effects on any Sound using @:

Effect What it does
Gain(amount) Multiply amplitude
Decay(duration) Exponential envelope (timedelta)
LowPass(hertz) One-pole lowpass filter
HighPass(hertz) One-pole highpass filter
Echo(duration) Single-tap delay
Delay(time, fb, mix) Feedback delay with dry/wet blend
Gate(duration) Hard cut to length
FadeIn(duration) Linear ramp up from silence
FadeOut(duration) Linear ramp down to silence
Reverse Reverse the buffer
Drive(amount) Tanh saturation
Clip(threshold) Hard-limit peaks
Normalize(peak) Scale so the loudest sample = peak
Tremolo(hertz, depth) Amplitude modulation
BitCrush(bits) Reduce bit depth (lo-fi)
Humanize(velocity) Subtle gain variation

Quick start

from datetime import timedelta
from songtools.lib import (
    Sound, Key, KeyRoot, Scale, Quality,
    Degree, Decay, LowPass, WavFile
)

# Create a simple tone
tone = Sound.tone(440.0, 44100)

# Apply transformations and effects
# A C-Major chord sequence with a lowpass filter
melody = (tone @ Key(KeyRoot.C, Scale.MAJOR, Quality.TRIAD) @ Degree.I) @ LowPass(2000)

# Sequence notes
song = Sound.sequence(melody @ Decay(timedelta(seconds=0.5)), tone @ Decay(timedelta(seconds=0.2)), bpm=bpm)

# Play or Save
song.play()
WavFile("output.wav").write(song)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

songtools-0.4.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

songtools-0.4.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file songtools-0.4.0.tar.gz.

File metadata

  • Download URL: songtools-0.4.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for songtools-0.4.0.tar.gz
Algorithm Hash digest
SHA256 9a77a4978d3630a9740cd30fe674c5628125f71a9706d2d745222265a6a9e69a
MD5 2384936803e5e00aea8ae56dbae3404b
BLAKE2b-256 20c1ebbcb141b5bc421fd252e7be03da7dae1ecdd35fcf9848dd3c71db8eefe2

See more details on using hashes here.

File details

Details for the file songtools-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: songtools-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for songtools-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1219b482b9fc08bd1628872d34cd4917c30d70ab04a5dae4b4a4d52b8395f165
MD5 0fdf563403a60418ae2d4ea763d75d3f
BLAKE2b-256 3ba5650881c3bd0d6bc10eacbde98f8daaa3a3e315cc76144352932d0750d953

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page