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 97841abd84 Add arrange of Dimension of Reverie 2022-04-10 16:19:55 +08:00
dimension-of-reverie Add arrange of Dimension of Reverie 2022-04-10 16:19:55 +08:00
pokemon-gsc-mainmenu Add demo of stereo capabilities 2022-04-09 11:36:05 +08:00
LICENSE Initial commit 2022-04-05 22:52:30 +08:00
README Better function name than "execute" 2022-04-08 13:35:08 +08:00
bad-apple.sh Better function name than "execute" 2022-04-08 13:35:08 +08:00
casket-of-star.sh Better function name than "execute" 2022-04-08 13:35:08 +08:00
eternal-shrine-maiden.sh Better function name than "execute" 2022-04-08 13:35:08 +08:00
hakurei-shrine-grounds.sh Add arrange of Hakurei Shrine Grounds 2022-04-08 16:31:16 +08:00
libsox.sh Better function name than "execute" 2022-04-08 13:35:08 +08:00
martsa-ng-bayan.sh Add arrange of Martsa ng Bayan 2022-04-09 21:51:23 +08:00
myplay-repeat.sh newline 2022-04-08 13:35:42 +08:00
mysox.sh newline 2022-04-08 13:35:42 +08:00
sleeping-terror.sh Better function name than "execute" 2022-04-08 13:35:08 +08:00

README

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

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

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

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:${fs[4]}"
)

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, though I'm not sure why you'd do that
)

createSoxPipes # Useful for dividing the part that loops and the part that doesn't

# Loop start
setTempo 160 # Change the BPM if needed

notes=( # Don't forget to reset the notes array. Don't append.
 "$dei:${fs[5]}"
 "$dei:${c[6]}"
 "$ei:${as[5]}"
 "$ha:${as[5]}"
 "$ei:${as[5]}"
)
function commonNotes {
 notes+=(
  "$si:${cs[5]}"
  "$si:${gs[4]}"
  "$si:${fs[4]}"
  "$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.