Thursday, August 18, 2022

πŸ†• πŸŽ‰Version 5.2.3 πŸ†• HZ# function πŸͺ²"Preprocessing Phase"

I follow a "release early, release often" release management philosophy, and a "small/incremental" change management philosophy for every new version of BASIC Anywhere Machine.

Although I've found upgrades of TiddlyWiki from one version to a newer one smooth no-brainers, I consider an upgrade of BASIC Anywhere Machine from one version of TiddlyWiki to a newer version as a noteworthy upgrade.

Changes to be found in today's new version of BASIC Anywhere Machine has the following worth:

  • Upgrade from TiddlyWiki 5.2.0 to TiddlyWiki 5.2.3
  • New Hz#(note$) function
    • This function takes a string represention of a musical note (a named note at a specified octave) and returns the matching frequency number
  • Improvements to BASIC Anywhere Machine's "Preprocessing Phase"

About BASIC Anywhere Machine TiddlyWiki upgrades.

On the rare occasion that an upgrade causes an issue, it can take a long time to discover the problem.  So just to play it safe, I will be keeping the previous version available in an archive.  I will continue archiving versions of BASIC Anywhere Machine (and the matching Programming Reference) whenever BAM undergoes any significant change.

About the version number scheme

All BASIC Anywhere Machine instances will have version numbers that match the TiddlyWiki version number.  The current version of BASIC Anywhere Machine will also include the date of the last edit made to that version of Anywhere Machine.

To find the version number of any version fo BASIC Anywhere Machine, click on BAM's "Help" menu, and click on the "About BASIC Anywhere Machine" menu item.  A first iteration of the feature in today's new version of BASIC Anywhere Machine:



About the HZ#(note$) function

I recently added a "_SNDWAVE" statement to set the sound wave pattern (sine, square, sawtooth, triangle) for all subsequent SOUND statements.  (Syntax:  SOUND frequency, duration)

After I posted a sound demo on reddit, "zxdunny" suggested consider an imrpovement: allow the option of specifying a note instead of a frequency.

Hence the HZ#(note$) function.

Instead of coding:
SOUND 587.33, 3

We can now code:
SOUND "D5",3
  • "D5" means the note D in octave 5

About the implementation of HZ#

I didn't feel like implementing the function in the interpreter (i.e write the javascript back-end for the function), and I decided to instead showcase BASIC Anywhere Machine's dynamic code generation features (TiddlyWiki's transclusion and "wikification" capabilities) that happen in the "preprocessing phase" or BASIC program execution.

(Bear with me: I'm still trying to figure out how to properly word all of this.)

Here's what I did:

First, I did was created a musical notes dictionary tiddler consisting of name-value pairs:  notes (concatenation of note name and note octave) and frequency values.  This is single-source multipurpose content which can be used to dynamically generate BASIC code in the preprocessing phase and to generate formatted documentation.

Next, I created a BASIC module that defines the HZ# function, but also has TiddlyWiki scripting to generate BASIC code.  The script uses as input the content of the musical notes dictionary tiddler, generating "SetLocalStorageItem()" lines of code to store each name-value pair in browser local storage.  When called, the HZ# function looks up frequencies for notes with GetLocalStorageItem().

To test everything out, I created the "Amazing Grace" program which plays a crude rendition of the melody:


About the "Preprocessing Phase" and Improvements

Preprocessing phase?  Macro/scripting process?

Not sure what to call it, but BASIC Anywhere Machine uses this "thing" in multiple places:
  • at run time to resolve all TiddlyWiki syntax, if any, and generate the BASIC program that will get merged with the HTML and wwwBASIC javascript code to run the program in an iframe
  • to view a BASIC program as it would appear after the preprocessing phase
  • to export a BASIC program from BASIC Anywhere Machine
    • as a .BAS file
    • as a .BAS.HTML file
    • as a .RUN.HTML file
Today's new version of BASIC Anywhere Machine attempts to fix a problem with the interpreter getting  confused about line positions (not BASIC line numbers, but rather the positions of code lines), reporting the wrong positions of coding errors when adding code to a BASIC program with the include metacommand.

No comments:

Post a Comment

πŸ–₯ Flower Tesselation: Testing DRAW and recursive SUB's

This BAM program inspired by Richard Russell's "Flower-like tesselation" BBC BASIC program posted on Facebook . Created in ord...