'NumberNote$ by Dutchman 2025

'NumberNote$ Test program
'Remove /* and */ to run the test program
/*
SET ORIENTATION HORIZONTAL
NumberNote$.EqLen=3  ' if >0 then note-strings are of equal length
NumberNote$.CapStr=1 ' if 1 then note-strings in uppercase
PRINT " notes | Note numbers"
FOR i=0 TO 11
  FOR j=0 TO 9
    n=(i+j*12)
    n$=STR$(n,"###")
    IF j=0 THEN a$="|" ELSE a$=" "
    PRINT n$&"-"&NumberNote$(n)&a$;
  NEXT j
  PRINT
NEXT i
PAUSE 1
SET ORIENTATION 0
END
*/

DEF NumberNote$(nr) ' by Dutchman 2025
' This function returns a musical note-string by its number
' The value of 'nr' should be in the range of 0-119
' If 'nr' is in the range 0-11 then the bare note
' wiil be returned, thus without octave number
' If nr<0 or nr>119 then "Error" will be returned.
' If NumberNote$.EqLen is set to 1 on advance,
' then the note strings will be of equal length.
' IF NumberNote$.CapStr is set to 1 on advance,
' then note-string will be returned in uppercase.
' The function is not dependent on OPTION BASE.
'===================================================
  IF nr<0 OR nr>119 THEN RETURN "Error"
  ob=OPTION_BASE()
  OPTION BASE 0
  IF NOT Set THEN GOSUB Init
  Code$=Notes$(nr%12)
  IF nr>11 THEN Code$&=FLOOR(nr/12-1)
  IF NOT CapStr THEN Code$=LOWSTR$(Code$)
  IF EqLen THEN Code$=LEFT$(Code$&"    ",EqLen)
  OPTION BASE ob
  RETURN Code$
' ---------------- local subroutine
  Init:
  Restore TO Octave
  READ Octave$
  SPLIT Octave$ TO Notes$,i WITH ","
  Set=1
  RETURN ' from subroutine
Octave:
  DATA "C,C#,D,D#,E,F,F#,G,G#,A,A#,B"
END DEF

