midi source code chord progression gen cpg

Somewhere to chat about MIDI music creation, sequencers and related hardware

Moderators: Mug UK, lotek_style, Moderator Team

Post Reply
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2821
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

midi source code chord progression gen cpg

Post by charles »

hi
found this and have converted over to gfa 3.6tt
anyone have something similar to share?

Code: Select all

' sof
'
KILL "a:\cpg_2.lst"
LIST "a:\cpg_2.lst"
'
noteon|=&H90
defaultvelocity|=126
maxchords|=100
notebufsize&=12
notebuf%=FN allocmem(notebufsize&,0)
IF notebuf%>0
  DIM scale|(8),chord|(maxchords|,4),prog|(maxchords|),type_|(7)
  GOSUB setvar
  GOSUB setbuff(notebuf%)
  OPENW 0
  '
  REPEAT
    LOCATE 1,3
    PRINT "Chord Progression Generator "
    PRINT "CPG_2 for the ATARI ST "
    PRINT "by C.callaghan Atari ST after Jim McConkey Amiga  sourced from "
    PRINT "Atari ST original by Jim Johnson "
    PRINT "Published in Electronic Musician, April 1988, pp 22-30 "
    '
    GOSUB getscale
    GOSUB makeprog
    GOSUB makechords
    GOSUB play
    '
    LOCATE 1,10
    PRINT "Generate another progression (Y/N)?"
    a$=""
    WHILE a$<>"Y" AND a$<>"N"
      a$=UPPER$(INKEY$)
    WEND
    LOCATE 1,10
    PRINT SPACE$(40)
    '
  UNTIL a$="N"
  '
  CLOSEW 0
  ERASE scale|(),chord|(),prog|(),type_|()
  ~FN allocmem(0,notebuf%)
ELSE
  PRINT "not enough memory "
ENDIF
CLS
END
'
' ==========================================
PROCEDURE setbuff(adr%)
  LOCAL j&
  FOR j&=0 TO 3
    POKE adr%,noteon|          !0,3,6,9
    INC adr%
    POKE adr%,0                !1,4,7,10
    INC adr%
    POKE adr%,defaultvelocity| !2,5,8,11
    INC adr%
  NEXT j&
RETURN
PROCEDURE getscale
  LOCAL j&
  ' Clean out buffer
  WHILE BIOS(1,3)
    ~BIOS(2,3)
  WEND
  ' Now get scale
1:
  DATA 88,34,66,72
  DATA 43,39,47,68
  RESTORE 1
  FOR j&=1 TO 8
    READ scale|(j&)
  NEXT j&
RETURN
PROCEDURE makeprog
  DEFFN rn1(r|)=BYTE(ADD(r|*RND(-1),1))
  LOCAL j&
  FOR j&=1 TO SUB(maxchords|,1)
    IF j&=1
      prog|(j&)=1
    ELSE
      SELECT type_|(prog|(SUB(j&,1)))
      CASE tonic|
        ' was 6 ??
        prog|(j&)=FN rn1(7)
      CASE digress|
        ' was 3 ??
        prog|(j&)=FN rn1(4)
      CASE approach|
        prog|(j&)=1
        EXIT IF j&>4
      ENDSELECT
    ENDIF
  NEXT j&
  INC j&
  prog|(j&)=0
RETURN
PROCEDURE makechords
  LOCAL j&,root|,third|,fifth|
  j&=1
  WHILE prog|(j&)<>0
    root|=prog|(j&)
    third|=ADD(root|,1)
    third|=ADD(MOD(third|,8),1)
    fifth|=ADD(root|,3)
    fifth|=ADD(MOD(fifth|,8),1)
    chord|(j&,1)=SUB(scale|(root|),12)
    chord|(j&,2)=scale|(root|)
    chord|(j&,3)=scale|(third|)
    chord|(j&,4)=scale|(fifth|)
    INC j&
  WEND
RETURN
PROCEDURE play
  LOCAL j&
  j&=1
  WHILE prog|(j&)<>0
    ' instal note values
    POKE notebuf%+1,chord|(j&,1)
    POKE notebuf%+4,chord|(j&,2)
    POKE notebuf%+7,chord|(j&,3)
    POKE notebuf%+10,chord|(j&,4)
    '
    ~XBIOS(12,W:notebufsize&-1,L:notebuf%)
    '
    PAUSE 12*(INT(4*RND(-1))+1)
    '
    ' instal 'off' values
    POKE notebuf%+2,0
    POKE notebuf%+5,0
    POKE notebuf%+8,0
    POKE notebuf%+11,0
    '
    ~XBIOS(12,W:notebufsize&-1,L:notebuf%)
    '
    ' restore 'on' values
    POKE notebuf%+2,defaultvelocity|
    POKE notebuf%+5,defaultvelocity|
    POKE notebuf%+8,defaultvelocity|
    POKE notebuf%+11,defaultvelocity|
    INC j&
  WEND
RETURN
PROCEDURE setvar
  tonic|=1
  digress|=2
  approach|=3
  '
  type_|(1)=tonic|
  type_|(2)=digress|
  type_|(3)=digress|
  type_|(4)=approach|
  type_|(5)=approach|
  type_|(6)=digress|
  type_|(7)=approach|
RETURN
FUNCTION allocmem(size%,adr%)
  SELECT size%
  CASE 0
    RETURN MFREE(adr%)
  DEFAULT
    RETURN MALLOC(size%)
  ENDSELECT
ENDFUNC
'
' eof

The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
User avatar
Eero Tamminen
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2360
Joined: Sun Jul 31, 2011 1:11 pm

Re: midi source code chord progression gen cpg

Post by Eero Tamminen »

charles wrote: Mon Jun 07, 2021 5:51 pm found this and have converted over to gfa 3.6tt
Was the original code also Basic, or in some other language (if it was C, I would be interested in those sources too)?

What was the original code license / copyright?
jimmysword
Atarian
Atarian
Posts: 7
Joined: Fri Apr 02, 2010 12:19 pm

Re: midi source code chord progression gen cpg

Post by jimmysword »

Should this run in GFA Basic Editor?
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2821
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: midi source code chord progression gen cpg

Post by charles »

it will run in the gfa 3.6tt version
abd lonny has a newer gfa package for higher machnes called gbe strong possibility will function under it .

I really cant remember what original sources were written in .
I think I obtained from a fred fish amiga disk??? or a amiga source cd

if u want a line by line descrition or the source pm me and ib be glad to break it down for you.
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
jimmysword
Atarian
Atarian
Posts: 7
Joined: Fri Apr 02, 2010 12:19 pm

Re: midi source code chord progression gen cpg

Post by jimmysword »

Cool I got it working, thanks!

I did some reading about GFA Basic and MIDI out put and the examples I saw were sending bytes out with "Out 3", with 3 signifying the MIDI Out port.

I see in your code you do something else, using "POKE", what is happening there?
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2821
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: midi source code chord progression gen cpg

Post by charles »

poking is me setting up the array with holds the midi notes
I think I might submit another version with no poking ,gfa is flexable enough
I can use a byte array because the one in this example is a set length and if u follow it closely youll notice the channel values stay the same , its just the note and velocity values alter.
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2821
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: midi source code chord progression gen cpg

Post by charles »

as I promised

Code: Select all

' sof
'
KILL "b:\cpg_3.lst"
LIST "b:\cpg_3.lst"
'
noteon|=&H90
noteoff|=&H80
defaultvelocity|=126
maxchords|=100
'
notebufsize&=8
DIM notebuf|(notebufsize&)
DIM scale|(8),chord|(maxchords|,4),prog|(maxchords|),type_|(7)
GOSUB setvar
GOSUB setbuff(notebuf%)
OPENW 0
'
REPEAT
  LOCATE 1,3
  PRINT "Chord Progression Generator "
  PRINT "CPG_2 for the ATARI ST "
  PRINT "by C.Callaghan Atari ST after Jim McConkey Amiga  sourced from "
  PRINT "Atari ST original by Jim Johnson "
  PRINT "Published in Electronic Musician, April 1988, pp 22-30 "
  '
  GOSUB getscale
  GOSUB makeprog
  GOSUB makechords
  GOSUB play
  '
  LOCATE 1,10
  PRINT "Generate another progression (Y/N)?"
  a$=""
  WHILE a$<>"Y" AND a$<>"N"
    a$=UPPER$(INKEY$)
  WEND
  LOCATE 1,10
  PRINT SPACE$(40)
  '
UNTIL a$="N"
'
CLOSEW 0
ERASE notebuf|(),scale|(),chord|(),prog|(),type_|()
CLS
END
'
' ==========================================
PROCEDURE setbuff(adr%)
  LOCAL j&
  notebuf|(0)=noteon|
  FOR j&=1 TO 8
    IF ODD(j&)
      notebuf|(j&)=0
    ELSE
      notebuf|(j&)=defaultvelocity|
    ENDIF
  NEXT j&
RETURN
PROCEDURE getscale
  LOCAL j&
  ' Clean out buffer
  WHILE BIOS(1,3)
    ~BIOS(2,3)
  WEND
  ' Now get scale
1:
  DATA 88,34,66,72
  DATA 43,39,47,68
  RESTORE 1
  FOR j&=1 TO 8
    READ scale|(j&)
  NEXT j&
RETURN
PROCEDURE makeprog
  DEFFN rn1(r|)=BYTE(ADD(r|*RND(-1),1))
  LOCAL j&
  FOR j&=1 TO SUB(maxchords|,1)
    IF j&=1
      prog|(j&)=1
    ELSE
      SELECT type_|(prog|(SUB(j&,1)))
      CASE tonic|
        ' was 6 ??
        prog|(j&)=FN rn1(7)
      CASE digress|
        ' was 3 ??
        prog|(j&)=FN rn1(4)
      CASE approach|
        prog|(j&)=1
        EXIT IF j&>4
      ENDSELECT
    ENDIF
  NEXT j&
  INC j&
  prog|(j&)=0
RETURN
PROCEDURE makechords
  LOCAL j&,root|,third|,fifth|
  j&=1
  WHILE prog|(j&)<>0
    root|=prog|(j&)
    third|=ADD(root|,1)
    third|=ADD(MOD(third|,8),1)
    fifth|=ADD(root|,3)
    fifth|=ADD(MOD(fifth|,8),1)
    chord|(j&,1)=SUB(scale|(root|),12)
    chord|(j&,2)=scale|(root|)
    chord|(j&,3)=scale|(third|)
    chord|(j&,4)=scale|(fifth|)
    INC j&
  WEND
RETURN
PROCEDURE play
  LOCAL j&
  j&=1
  WHILE prog|(j&)<>0
    ' instal note values
    notebuf|(1)=chord|(j&,1)
    notebuf|(3)=chord|(j&,2)
    notebuf|(5)=chord|(j&,3)
    notebuf|(7)=chord|(j&,4)
    '
    ~XBIOS(12,W:notebufsize&-1,L:V:notebuf|(0))
    '
    PAUSE 12*(INT(4*RND(-1))+1)
    '
    ' instal 'off' values
    notebuf|(0)=noteoff|
    '
    ~XBIOS(12,W:notebufsize&-1,L:V:notebuf|(0))
    '
    ' restore 'on' values
    notebuf|(0)=noteon|
    '
    INC j&
  WEND
RETURN
PROCEDURE setvar
  tonic|=1
  digress|=2
  approach|=3
  '
  type_|(1)=tonic|
  type_|(2)=digress|
  type_|(3)=digress|
  type_|(4)=approach|
  type_|(5)=approach|
  type_|(6)=digress|
  type_|(7)=approach|
RETURN
'
' eof

The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
jimmysword
Atarian
Atarian
Posts: 7
Joined: Fri Apr 02, 2010 12:19 pm

Re: midi source code chord progression gen cpg

Post by jimmysword »

Oh I see now, you use XBIOS 12 (MIDIWS) to send a string to the MIDI out port with each of the bytes rather than multiple calls to Out 3. Is this just a style preference or is there a reason to prefer the XBIOS call?
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2821
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: midi source code chord progression gen cpg

Post by charles »

well just the personal pattern I choose when learning to program I suppose..
but I find its slighty faster with fewer cpu cycles , a lot less clutter in the code writing process....
might b worth mentioning xbios is low level too
so instead of opening up a channel using the open'o'#1,a$ and sending a string out ...
xbios will terminate fast without much mouse jolting as other midi interfacing does... out 3 is simply the roughest path midi could take , someone implemented that port to order supper over the fax line way back when , it cuts the mouse up and program hangs often
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
Post Reply

Return to “MIDI Software and Hardware”