Here is a transcription of code from an article on music syntax in APL2 and some simple MIDI The article reference is in the code. If you have an ACM membership you should be able to download The PDF of the article
Tom McGuire
NB. MusicalSyntax.ijs - J implementation of functions from APL90 NB. paper: Friis ES, Jordan S "Musical Syntactic and Semantic Structures in NB. APL2" NB. J Author: Tom McGuire NB. splice =: 13 : ',&.>/ y' scale =: 0 2 4 5 7 9 11 Notes =: 'ABCDEFG' ChordNames =: (1$'M');(1$'m');'M7';'m7';(1$'o') ChordTypes =: 'major';'minor';'major7';'minor7';'diminished' CS =: (1$'C');'C#';(1$'D');'D#';(1$'E');(1$'F');'F#';(1$'G');'G#';(1$'A');'A#';1$'B' NB. DTmajor diatonic chords for a major scale NB. used as indexes into ChordNames and ChordTypes DTmajor =: 0 1 1 0 0 1 4 M =: 0 4 7 m =: 0 3 7 o =: 0 3 6 M7 =: 0 4 7 11 m7 =: 0 3 7 10 NB. Midi event creation note_on =: 13 : '144,y,64' note_off =: 13 : '128,y,64' Scale =: 60 + scale NB. middle C major scale NB. diatonic tonalities generates chords of a major scale DT =: 13 : ' splice"1 (DTmajor { ChordNames),.~ scale { (CS i. <y) |. CS' NB. arp - arpeggiate a chord into its 3 note pitches arp =: 13 : '( ". 1}.y) { (CS i. <1{. y) |. CS' NumToName =: 3 : 0 'octave pc' =. 0 12 #: y octave =. ": octave - 1 pc =. >pc { CS pc,octave ) NB. example usage NB. NumToName 60 - returns middle C with its octave NB. NumToName each ;/60 + scale - produces all the notes in middle C with octave NB. DT 'C' - will produce boxed list of diatonic chords for Cmajor scale NB. DT each CS - produces all 12 distinct diatonic tonalities NB. arp each DT 'C' - produces a boxed list of 3 note diatonic tonality chords NB. NB. MIDI event parsing NB. X =: 144 64 64 144 67 64 144 71 64 128 64 64 128 67 64 128 71 64 NB. EVENTS =: _3 <\X NB. NB. to get the notes in the EVENTS NB. 1&{ each (;144&e. each EVENTS)#EVENTS NB. NB. to convert the note names: NB. NumToName each 1&{ each (;144&e. each EVENTS)#EVENTS
> On Mar 28, 2020, at 5:27 PM, Devon McCormick <devon...@gmail.com> wrote: > > Hi - > has anyone done work with generating music or musical phrases in J? I'm > helping someone develop a music training game that starts by generating > sounds with a particular key, tempo, and phrase length. The idea is to > help students to train their ears by testing them on their ability to play > back a randomly-generated musical phrase. > > I've told my collaborator that I think the generation part should be > relatively straightforward but I am not schooled in music, so I'm not sure > how to start. > I'm guessing that the second part of comparing the user's response to the > generated phrase will be more difficult but I'd like to get any kind of > start I can. > > Does anyone have any ideas about this? > > Thanks, > > Devon > > -- > > Devon McCormick, CFA > > Quantitative Consultant > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm
---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm