I fixed up the n2p routine, although not in the same output format as the book 
(“Cybernetic Music”) it seems to track the relative octave increases and 
decreases from the examples. I apologize for the not very J-ish style for the 
support routine ‘ROCT’ (new routine not part of the original APL).

NB. ROCT - relative octave processing. The goal is to move down
NB. a list of note numbers and record upticks and down tics in 
NB. octave.
NB. x is the starting relative octave (usually 0)
NB. y is the array of notes
ROCT =: 4 : 0
aoct =. <.y%TONSYS
smoutput aoct
loct =. x
oct =. 1$loct
for_i. aoct do.
  delta =. i - loct
  oct =. oct, i - loct 
  if. delta ~: 0 do.
    loct =. i
  end.
end.
oct
)

NB. N2P - in J using boxing to generate and display pitch names
NB.       this makes it much easier to manipulate than the APL
NB.       routines originally developed
n2p =: 3 : 0
NB. Octave would be the relative octave away from main octave
NB. The octave is found by dividing by the # of tones in an octave
NB. ie. divide by TONSYS and then using floor <. to produce the 
NB. integer truncation. Then use format ": to turn it all into
NB. Text
octave =. ": each ;/ }. 0 ROCT y
NB. The following will map a note to it's text pitch name
pitch =. (TONSYS|y) { _3 <\NOTENAME
(('0';' ')&stringreplace each octave),:pitch
)


 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to