Easy music generation with SoX and GNU bash
This repository has been archived on 2023-08-15. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Job Bautista 7e31da0911 Add arrange of High Pitch Addicts Vocal Range Test
Also fixed if statement in myplay-repeat.sh, forgot to commit that
2022-04-21 15:31:16 +08:00
dimension-of-reverie Add arrange of Dimension of Reverie 2022-04-10 16:19:55 +08:00
high-range-test Add arrange of High Pitch Addicts Vocal Range Test 2022-04-21 15:31:16 +08:00
judas-kiss Add arrange of Treacherous Maiden ~ Judas Kiss 2022-04-14 13:28:47 +08:00
pokemon-gsc-mainmenu New major features 2022-04-16 10:43:18 +08:00
LICENSE Initial commit 2022-04-05 22:52:30 +08:00
README Added arrange of Green-Eyed Jealousy 2022-04-20 17:54:39 +08:00
apparitions-night.sh Add arrange of Apparitions Stalk the Night 2022-04-13 19:41:34 +08:00
bad-apple.sh Better function name than "execute" 2022-04-08 13:35:08 +08:00
because-princess-inada.sh Add arrange of Because Princess Inada is Scolding Me 2022-04-11 23:19:14 +08:00
casket-of-star.sh Better function name than "execute" 2022-04-08 13:35:08 +08:00
dark-side-of-fate.sh The arrange of Dark Side of Fate turned out to be incomplete 2022-04-16 14:49:11 +08:00
eternal-shrine-maiden.sh New major features 2022-04-16 10:43:18 +08:00
green-eyed-jealousy.sh Forgot to center the ASCII art :\ 2022-04-20 17:57:07 +08:00
hakurei-shrine-grounds.sh Add arrange of Hakurei Shrine Grounds 2022-04-08 16:31:16 +08:00
hartmann-youkai-girl.sh Add arrange of Hartmann's Youkai Girl 2022-04-12 18:04:41 +08:00
hartmann-youkai-girl_chaos.sh Koishi RNG 2022-04-16 18:56:11 +08:00
libsox.sh Added arrange of Green-Eyed Jealousy 2022-04-20 17:54:39 +08:00
martsa-ng-bayan.sh Add arrange of Martsa ng Bayan 2022-04-09 21:51:23 +08:00
myplay-repeat.sh Add arrange of High Pitch Addicts Vocal Range Test 2022-04-21 15:31:16 +08:00
mysox.sh newline 2022-04-08 13:35:42 +08:00
rabbit-has-landed.sh Update README for 3/4/5/6-note harmony feature 2022-04-18 19:24:26 +08:00
sleeping-terror.sh New major features 2022-04-16 10:43:18 +08:00

README

libsox.sh
---------

A library for GNU bash making it easier to create music with the power of SoX
synths.

If you're one of these people:

- a Bash programmer
- suck at reading sheet music
- finds MML too difficult
- too lazy to learn FamiTracker
- think that scientific note duration is the best thing since sliced bread

Then try this crappy library of mine!

Some features of this library:

- Easy to write syntax for inputting notes ("$duration:${key[pitch]}")
 - Inspired from korobeiniki.sh of the dsuni/bashtris repository
- Supports two-note harmonies ("$duration:${key1[pitch1]},${key2[pitch2]}")
 - Must be the same duration and instrument
- Optionally supports 3/4/5/6-note harmonies as well
 -"$duration:${k1[p1]},${k2[p2]}*${k3[p3]}_${k4[p4]@${k5[p5]}}^${k6[p6]}"
 -You need to call "enable3456Harmony" to enable this feature
 -For ALSA, you also need to set sox's audio processing buffer to 16384 bytes,
  else you will get underrun
- Supports every synth type included in SoX
- Adheres to the Unix philosophy of "do one thing and do it well"

What this library doesn't support:

- Using your own samples (just use FamiTracker or a DAW for that)
- Harmonies with different durations or instruments
- POSIX compatibility

Usage
-----

Simply source libsox.sh into the script containing the music. Example scripts
are included in this repository.

Example child script syntax
---------------------------

./music.sh | xargs play -S -V1 # Plays into SoX once

./music.sh | xargs ./myplay-repeat.sh 1 # Plays into SoX twice

./music.sh | xargs ./mysox.sh music.wav # Saves into "music.wav" using SoX

./music.sh | head -n +37 | xargs play -S -V1 ; ./music.sh | tail -n +37 |
 xargs ./myplay-repeat.sh 3    # Plays line 1 to 37 of music.sh's output once,
                                 then plays the rest thrice

./music.sh | xargs ./mysox.sh - | cvlc - # Saves into stdout then pipes it into
                                           vlc
./music.sh > music.txt         # Redirects music.sh's output to a text file

./music.sh | xclip -i          # Copies music.sh's output to XA_PRIMARY

Usual child script format
-------------------------
##############################################################################
#!/bin/bash

: '
Long copyright boilerplate goes here.
It's up to you though if you want to include it or not.
'

source path/to/libsox.sh

declare textintro='
Optional ASCII art and info about the music goes here.

'

setTempo 120 # In BPM

setDefaultSynthType sin # Consult sox's manual. Default is sine

notes=(
 # "$duration:${note[pitch]}"

 # Basic durations:
 #  $fu = whole note
 #  $ha = half note
 #  $qu = quarter note
 #  $ei = eighth note
 #  $si = sixteenth note
 # We use scientific pitch notation

 "$ha:0" # This is how to do a half rest

 "$si:${c[5]}" # A sixteenth C note in the 5th octave
 "$ei:${gs[4]}" # An eighth G sharp in 4th octave
 "$qu:${gf[4]}" # A quarter G flat in 4th octave
 "$qu:${gb[4]}" # Also a G flat
)

function repeatingNotes { # Use bash functions to repeat parts of your music
 notes+=( # use += to append to the notes array
  "$qu:${cs[4]}"
  "$qu:${ds[4]}"
  "$qu:${e[3]}"
  "$qu:${gs[4]}"
 )
}
repeatingNotes # Don't forget to call your function
notes+=( # continue adding notes
 "$ei:${cs[4]}"
 "$ei:${cs[4]}"
 "$ei:${ds[4]}"
 "$ei:${ds[4]}"
)
repeatingNotes # Will repeat the earlier C sharp, D sharp, E, and G sharp
               # quarter notes
notes+=(
 "$dei:${b[2]}" # Dotted notes are supported
 "$tqu:${a[3]}" # Triplets are supported
 "0.02:${gs[4]}" # You can do custom durations
 "0.05:489 # Custom frequencies too
)

createSoxPipes # Will reset the notes array too
echo # Useful for distinguishing the part that loops and the part that doesn't

# Loop start
setTempo 160 # Change the BPM if needed

setDefaultSynthType pluck # You can change the synth type midway.

notes+=(
 "$dei:${fs[5]},${gs[5]}" # You can do two-note harmonies
 "$dei:${c[6]}"
 "$ei:${as[5]}"
 "$ha:${as[5]}"
 "$ei:${as[5]}"
)
function commonNotes {
 notes+=(
  "$si:${cs[5]}"
  "$si:${gs[4]}"
  "$si:${fs[4]}"
 )
 silence # Required if you're using a synth type that doesn't support freq=0
 notes+=(
  "$si:${e[4]}"
  "$si:${cs[5]}"
 )
}
commonNotes; commonNotes;
notes+=(
 "$qu:${c[4]}"
 "$qu:${cs[4]}"
 "$qu:${ds[4]}"
 "$ei:${f[4]}"
 "$si:${as[4]}"
 "$dei:${f[4]}"
)
commonNotes
notes+=(
 "$dei:${f[4]}"
 "$ei:${as[4]}"
 "$ei:${a[4]}"
 "$ei:${a[4]}"
 "$ei:${as[4]}"
 "$si:${a[4]}"
 "$si:${as[4]}"
 "$si:${f[5]}"
)

createSoxPipes

##############################################################################

License
-------

Copyright (C) 2022 Job Bautista

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.