Nichts als die varheit

paw 2 - the plain audio workstation

tags: audio, multitracking, MIDI, sequencing, OpenBSD, sndio, shell

Paw[1] is a simple DAW (digital audio workstation) implemented as a Bourne shell script. It is text-based and runs in a terminal. In essence, paw is a frontend to the sndio[2] audio/MIDI framework and its accompanying tools. It can be small by standing on the shoulders of giants. It runs on OpenBSD and other Unix-like operating systems where sndio is available.

Paw supports audio multitracking, MIDI sequencing, and composition/musical notation. One reason it exists is to make people aware of some powerful tools that are freely available: The already mentioned sndio (as a no-fuss audio system), midish[3] (for MIDI sequencing), and Mup[4] (for music typesetting).

The inevitable screenshot of an imaginary recording session with four tracks:

stop: [127] 3/4 guitar[1] {4 4}@120#0:0:0 {0}:

Preparation

Paw assumes that the audio server sndiod[5] is running. Consult your operating system documentation for details. Basically, sndiod should be started using something like the following flags:

sndiod -f rsnd/0 -s default -t slave -s mmc -t off -m mon -s mon
In this configuration, the first audio device (rsnd/0) will be used. The sub-device “mmc” is only required for audio/MIDI synchronization. But it does do no harm to add it anyway. The optional sub-device “mon” should be added if you want to be able to record what the system is playing back.

Basic usage -- audio multitracking

Simply download, extract and add paw to your PATH. Open a terminal, switch to an empty directory and start your first session (your prompt might contain additional status information if midish and/or Mup are installed):

$ paw
stop. [127] 0/0 master[2]:

Let's add an audio track by pressing  a :

Enter new audio track name: guitar
guitar: channels (1=mono, 2=stereo) [2]: 1
stop. [127] 1/1 guitar[1]:

Paw has created a new mono audio track named “guitar.wav”. It is armed for recording as indicated by the alarmingly red track label. Plug your guitar amp into your sound card. Or use your microphone to capture an acoustic instrument.

To adjust the recording level, hit  , . This will enter “idle” mode and display a simple level meter. It will capture whatever input is marked for recording in your audio device.

level [ 30] [0000000000>                                    ]

Finally, hit  space  to start recording and jam along. Paw counts the seconds while you do the heavy work.

...
rec. 45s
...

Hit  .  to stop recording.

stop. [127] 1/1 guitar[1]:

Your first recording is now finished. Hit  space  to listen to what you have been able to achieve. If you are not satisfied, hit  .  to stop the playback. Press  r  to arm the selected track (guitar) for recording again, and repeat the recording process as above until you get the recording right.

You can now add and record additional tracks as required. Why not sing along to your beautiful guitar track? Hit  a  again:

Enter new audio track name: vocals
vocals: channels (1=mono, 2=stereo) [2]: 1
stop. [127] 2/2 vocals[1]:

If you have already forgotten how to start the recording, hit  h  for a list of keyboard shortcuts:

   h/H  view shortcuts/prompt info
 space  record
     ,  idle
     .  stop
     a  add audio track
   k/j  select track up/down
   g/G  select first/last track
   -/+  volume -/+
 m/s/r  toggle mute/solo/record
   l/L  list tracks once/always
     T  mixdown tracks
     x  exit

As you can see, you can browse through your tracks using  k  and  j , and you start to wonder which text editor the author is using. You can adjust the volume of each track, or mute or solo it. Once you are satisfied with your mix, hit  T  to mixdown your individual tracks to a single file “mixdown.wav”. Send it to your favorite producer and get rich or mocked.

You can exit paw by hitting  x . If you run it again in the same directory, it will pick up all the audio tracks (except “mixdown.wav”) automatically.

Advanced usage — MIDI sequencing

If the amazing text-based MIDI sequencer midish is installed on your system, paw will automatically use it (provided it is installed at /usr/local/bin/midish). If it is installed in a different location, tell paw where to find it using “paw -M path”.

To see all the command line options, run “paw -h”:

paw - plain audio workstation
Usage: paw [-defghikmrMS] [file]
        -d debug
        -e encoding             [s24]
        -f <audio device>       [snd/default]
        -g <MMC audio device>   [snd/mmc]
        -h show this usage
        -i <midish MTC device>  [9]
        -k <monitor device>     [snd/mon]
        -m <MIDI device>        [midithru/0]
        -r <sample rate>        [48000]
        -M midish path          [/usr/local/bin/midish]
        -S mup path             [/usr/local/bin/mup]
        -T mup template         [<builtin>]

Paw requires a MMC-controlled audio sub-device for synchronizing audio and MIDI (see sndiod flags above). This sub-device is expected to be named “mmc”. A different name can be passed to paw with “paw -g snd/whatever”. The following minimal configuration “$HOME/.midishrc” is required for midish:

dnew 0 "midithru/0" rw
dnew 9 "snd/mmc" rw

If device “snd/mmc” uses a different number, pass it to paw using “paw -i num”.

If you have additional MIDI hardware, add it to your configuration as well. You will most certainly need some input device like a MIDI keyboard:

dnew 0 "midithru/0" rw
dnew 1 "midi/0" ro      # MIDI keyboard
dnew 9 "snd/mmc" rw
fnew keys
fmap {any 1} {any 0}    # pass keyboard events to midithru/0

If you don't have a hardware MIDI synth, you can use a software synth like fluidsynth[6]. You will also need a soundfont for fluidsynth, e.g., GeneralUser GS[7]. This is just one example, you can basically use any software synth that can be controlled by MIDI. For instance, the freely available LMMS[8] includes a variety of different synths with lots of nice presets, and is an amazing DAW in its own rights.

Once everything is set up, recording MIDI tracks is as simple as recording audio tracks. When paw has MIDI enabled, some new shortcuts become available:

     A  add MIDI track
     :  midish command
     M  midish prompt
     =  select measure
   </>  measure -/+
   (/)  range -/+
     o  toggle loop
     q  quit (save)

If a synth is connected to “midithru/0”, simply press  ,  to switch to idle mode. You should now be able to play the synth using the hardware MIDI keyboard.

Hit  .  for stop mode, and add a new MIDI track using  A :

Enter new MIDI track name: piano
stop: [127] 3/3 piano[M]:

As usual, the new track is armed, and you can start recording by hitting  space , and stop using  . . During recording, you should hear a metronome banging in your softsynth.

Starting playback with  space  will synchronize audio and MIDI tracks indicated by the prompt “play:” instead of “play.”. You can jump around in your MIDI tracks by selecting a start measure using the  < ,  > , and  =  keys. A selection may be set using  (  and  ) . Use  o  to toggle loop mode for the selected measures. The start measure is displayed next to the # label, followed by the selection length, followed by the loop mode status. The current time signature and tempo (BPM) are displayed before the # label. Additionally, the current quantization step and midish filter (if any) are displayed before the time signature.

The audio and MIDI tracks can be listed with  l . You can toggle a permanent listing of tracks with  L . There are two ways to issue commands to midish: Single commands can be sent using the shortcut  : , then typing the command and pressing  Enter . Hitting  M  will yield a midish prompt. You can now enter multiple commands just like you would if you were using midish directly. Enter a single dot  .  to return to paw.

Detailed information about the commands and the inner workings of midish can be obtained from its excellent documentation[9].

Note that mixing down your project with  T  will not include the MIDI tracks. The mixdown function is stricly limited to audio. It is however possible to include the playback of your softsynths into a single audio file if you have enabled a monitor device (“mon”) in your sndiod flags (see above). Select the “master” track (e.g., using  gk ), and arm it for recording by pressing  r . Now, start the playback of your project with  space . This will record everything the system is playing in realtime until you hit  .  to stop the recording. Look for the file “master.wav” in your project folder. Just like the file “mixdown.wav” it will be ignored when launching a paw session. You will have to rename it if you want to include it in your project as well.

If you leave paw by hitting  q , the midish project will be saved as “0.msh”. It will automatically be loaded in the next session. Note that exiting with  x  will discard the current MIDI project.

To save the project at any time, enter :save "0.msh" (or any other desired file name). Load projects explicitly using :load "...". Standard MIDI files can be imported/exported into/from midish with :import "..." and :export "...", respectively. Note that loading midish projects, or importing MIDI files will replace the currently loaded project.

Getting funky — composing using Mup

Apart from the interactive recording of MIDI tracks with midish, paw also provides access to the Mup music publication program. If Mup is installed in /usr/local/bin/mup, it will be enabled automatically. Otherwise, tell paw where to find it using the command line switch “-S”.

Paw provides slots for up to nine musical scores. These are accessed using the shortcuts  1  through  9 . Switching to one of these slots from slot 0 automatically saves the current midish project to slot  0 . The currently selected slot is indicated by the last number of the paw prompt (here: slot 1):

stop: [127] 0/0 master[2] {4 4}@120#0:0:0 {1}:

Editing a musical score

Press  e  to edit the currently selected slot in your $EDITOR or vi. If this slot is empty, a simple template will be preloaded:

score
        staffs=1
        time=common
        key=c major
        bracket=1-1
music
        midi 1: 0 "channel=1";
        midi 1: 0 "program=1";
// enter measures here:

You can override this template with a custom version using the command line switch “paw -T ”. Let's add two silly measures with quarter notes to this score:

score
        staffs=1
        time=common
        key=c major
        bracket=1-1
music
        midi 1: 0 "channel=1";
        midi 1: 0 "program=1";
// enter measures here:
1: 4c;d;e;f;
bar
1: 4e;d;g;c;
endbar

Afterwards, save the file in your editor. Paw will now invoke Mup to get a MIDI rendition of the score into midish. If your score contained errors, they will be shown on the console. You can now press any key to return to the editor and fix those errors, or give up for now using  q .

If all went fine, hit  space  to listen to your hit piece. If yet another piece of software, the PostScript viewer GV[10], is installed on your system, you can marvel at a typeset version of your score after pressing  p .

A simple score created with MUP

Let's add another staff to this beautiful piece, playing on MIDI program 41, which would select something like a violin:

score
        staffs=2
        time=common
        key=c major
        bracket=1-2
music
        midi 1: 0 "channel=1";
        midi 1: 0 "program=1";
        midi 2: 0 "channel=2";
        midi 2: 0 "program=41";
// enter measures here:
1: 4c;d;e;f;
2: 2a;g;
bar
1: 4e;d;g;c;
2: 2e;c;
endbar
A simple score with two staffs

PDF versions of your score can also be obtained if Ghostscript[11] is available on your system. Hit  P  to view the score in your system's PDF viewer.

Mup is an extremely powerful tool. Make yourself familiar with the command syntax by reading its excellent User's Guide[12].

Where to go from here?

All the files created by paw can easily be reused in other projects. Audio wave files, and standard MIDI files can be imported into any DAW. Or the other way around: Export audio and MIDI tracks from another DAW into an empty directory and launch paw there. Also, the typeset scores in PostScript and PDF format can be used in other projects. Your imagination defines the limits. Have fun using paw.

References

[1] https://varheit.de/paw/paw2.tar.gz (Paw)
[2] https://sndio.org/ (sndio)
[3] https://midish.org (midish)
[4] http://www.arkkra.com/ (Mup)
[5] https://man.openbsd.org/sndiod (sndiod)
[6] https://www.fluidsynth.org/ (fluidsynth)
[7] https://schristiancollins.com/generaluser.php (GeneralUser GS)
[8] https://lmms.io/ (LMMS)
[9] https://midish.org/manual.html (documentation)
[10] https://www.gnu.org/software/gv/ (GV)
[11] https://www.ghostscript.com/ (Ghostscript)
[12] http://www.arkkra.com/doc/uguide/index.html (User's Guide)

Changes in version 2

• Add command line switches '-r' and '-e' to specify the sample rate and encoding for recorded files. See the man page of aucat for the encoding formats. • When recording new audio tracks, paw now asks for the number of channels. Previously, paw always recorded in stereo. Upon startup, paw tries to read the number of audio channels from audio tracks. If this fails, and you want to re-record an existing track, paw will ask for the number of channels. • Slot files are now named .{mid, msh, mup, pdf, ps} instead of using the prefix paw-. Simply rename old slot files to continue to use them. • In idle mode, a simple monaural level meter is displayed. This can be used to adjust the audio device recording level. • No log file is written anymore by default. Use -d to log to standard error or redirect standard error to a file. The shortcut  v  has been removed. • MIDI tracks are now also listed (after the audio tracks). New MIDI tracks can be added with  A . They can be muted, soloed, and armed for recording just like audio tracks. The volume of MIDI tracks cannot be adjusted. The MIDI status now includes the following information: Quantization step (if set), current filter (if set), time signature, tempo in BPM, starting measure, selection length, and loop mode. The new shortcuts  (  and  )  determine the number of selected measures. Loop mode may be toggled with  o . If loop mode is enabled, the selected measures are repeated infinitely. Audio playback comtimues as usual in loop mode. • Tracks are now toggled for recording using  r  instead of  R . The recording mode previously started with  r  has been removed. Recording is now started using  space  if audio or MIDI tracks are armed. • Code has been refactored. • Bugs have been fixed.

License

paw -- plain audio workstation

(c) 2024 Dirk-Wilhelm Peters <peters (at) schwertfisch (dot) de>

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.