[tw5] "Hz#" function example: TiddlyWiki for generating BASIC code at runtime

In BASIC Anywhere Machine, the SOUND statement is used to play sound frequencies for a specified length of time.

Syntax: SOUND frequency, duration

Typing in frequencies for specific musical notes is a pain.

Intead of typing in frequency numbers for every note, it would be nice to be able to just type in the note (i.e. note name and octave.) For example:

SOUND Hz#(“C1”), 18 instead of SOUND 32.703, 18

If I am going to associate a NoteName+NoteOctave with a frequency for every note and octave, I want to do that just once. Only once, with ability to reuse that everywhere for all needs, in particular: documentation and an auto-generated code library.

As per screenshots below, using TiddlyWiki to store date and generate code: that’s pretty cool.

(Might be tweaking this if I run into problems, but working fine so far.)

The basic program with macro to include the Hz# tiddler, which takes care of generating the Hz# function:
Screenshot 2022-08-15 10.01.19 PM.png

The data dictionary with NoteName+NoteOctave and frequency (“name-value”) pairs:

The "Hz#(note$) tiddler rendering the Hz# function:

1 Like

I’ve got my prototype Hz# function working. Done with BASIC statements/functions with some macro help from TiddlyWiki.

A “Musical Notes Dictionary” tiddler to store the name-value pairs of NoteNameAndOctave and frequency.

The “Hz#(note$)” tiddler that defines the Hz# function.

  • the quickest no-fuss-no-muss approach involves putting in browser local storage all of the name-value pairs of musical notes, and getting the Hz# function to take the note$ parameter and look it up in browser local storage

  • the list of SetLocalStorage() statements is generated by TiddlyWiki at program run time

For any program in which I want to use Hz#, I add an “include” macro call at the top of the program: <<include “Hz#(note$)”>>

Sample program: Amazing Grace (crude first attempt)

1 Like