Generating MIDI files [SOLVED]

Get help with using AutoHotkey and its commands and hotkeys
florisvos
Posts: 20
Joined: 15 Apr 2016, 06:26
Facebook: https://www.facebook.com/floris.vos.77

Generating MIDI files [SOLVED]

07 Jun 2016, 04:55

Hi,

I'm working on a random music generator. I started it when I discovered SoundBeep so I now have a music generator that generates alot of soundbeeps in an interesting way. I'd love to convert it to MIDI, but not sure how to do it. I found an EXE file somewhere that was supposed to be able to do the job, but it was kind of technical, worked with the Command Prompt, so I really don't have a clue how to use it (FYI, it's this one: http://www.fourmilab.ch/webtools/midicsv/)

Now, could anybody help me with this?

I'll share my code in case anybody's interested: (beware, it's long)

Code: Select all


^6::
;MAIN ARRAYS:

FREQ_1		:= [16.35,17.32,18.35,19.45,20.6,21.83,23.12,24.5,25.96,27.5,29.14,30.87,32.7,34.65,36.71,38.89,41.2,43.65,46.25,49,51.91,55,58.27,61.74,65.41,69.3,73.42,77.78,82.41,87.31,92.5,98,103.83,110,116.54,123.47,130.81,138.59,146.83,155.56,164.81,174.61,185,196,207.65,220,233.08,246.94,261.63,277.18,293.66,311.13,329.63,349.23,369.99,392,415.3,440,466.16,493.88,523.25,554.37,587.33,622.25,659.25,698.46,739.99,783.99,830.61,880,932.33,987.77,1046.5,1108.73,1174.66,1244.51,1318.51,1396.91,1479.98,1567.98,1661.22,1760,1864.66,1975.53,2093,2217.46,2349.32,2489.02,2637.02,2793.83,2959.96,3135.96,3322.44,3520,3729.31,3951.07,4186.01,4434.92,4698.63,4978.03,5274.04,5587.65,5919.91,6271.93,6644.88,7040,7458.62,7902.13]
LADDER_1	:= [1,3,5,6,8,10,12,13,15,17,18,20,22,24,25,27,29,30,32,34,36,37,39,41,42,44,46,48,49,51,53,54,56,58,60,61,63,65,66,68,70,72,73,75,77,78,80,82,84,85,87,89,90,92,94,96,97,99,101,102,104,106]
CHANCES		:= [[0,0,0,0,8,11,15,17,21,31,32,37,37,37,37],[0,0,0,0,1,11,15,15,19,22,30,30,34,34,34],[0,0,0,0,1,11,15,15,19,29,30,30,34,34,34],[0,0,0,0,7,10,14,15,19,29,30,35,35,35,35],[0,0,0,0,5,8,12,14,18,28,29,33,33,33,33],[0,0,0,0,1,11,15,15,19,29,30,30,33,33,33],[0,0,0,0,1,11,15,15,19,27,28,28,31,31,31]]
PARTIALBARS	:= [[[0.5]],[[0.5,0.5],[1]],[[0.5,0.5,0.5],[1,0.5],[1.5]],[[0.5,0.5,0.5,0.5],[1,0.5,0.5],[1,1],[1.5,0.5],[2]],[[0.5,0.5,0.5,0.5,0.5],[1,0.5,0.5,0.5],[1.5,0.5,0.5],[2,0.5],[1,1,0.5]]]


;BAR ARRAYS:

BArtypes	:= [[1,1,1],[1.5,0.5,0.5,0.5],[2,1],[3],[2,0.5,0.5],[0.5,0.5,0.5,0.5,0.5,0.5],[3,3]]
Barchances	:= [0,1,6,20,40, 50,57,60]

;SETUP:

lower		:= 25
upper		:= 45
tone		:= 35
barnumber	:= 0
BArs		:= Object()
BArtones	:= Object()
ladder		:= Object()

; GENERATE MEASURES

loop 100 
{
barnumber++

;CHANGE LIMITS ON EACH TWELFTH BAR

if mod(barnumber,12) = 0
{
	
	if lower < 20
	{
	lower += 7
	upper += 7
	}
	else if upper > 50
	{
	lower -= 7
	upper -= 7
	}
	else
	{
	random, random, 0, 1
	direction := 1-2*random
	upper += 7 * direction
	lower += 7 * direction
	}
}


random, random, 1, 10

; LADDER MAKER
if random > 8
{
	BArtones[barnumber] := [0,0]
	BArs[barnumber] := [0,0]
	Ladder[barnumber] := [0,0]
	random, random,  0, 1
	direction := 1-2*random
	random, random, -1, 0
	length	  := 2**random
	random, loop,    3, 6	

		loop % loop
		{
		BArs[barnumber][a_index] := length
		tone += direction
		ladder[barnumber][a_index] := tone
		BArtones[barnumber][a_index] := freq_1[ladder_1[tone]]						
		}
		Barnumber++

	if mod(loop * length,3) != 0
	{	
	EXTRA := PARTIALBARS[round(mod(loop * length,3)/0.5)]
	random, random, 1, EXTRA.length()
	EXTRA := EXTRA[random]
	BArs[barnumber] := EXTRA
	BArtones[barnumber] := [0,0]
	Ladder[barnumber] := [0,0]


		loop % BArs[barnumber].length()
		{
		CHANCE := CHANCES[mod(tone,7)+1]
			random, random, 1, CHANCE[CHANCE.length()] 
			tone -= 7
				loop % (CHANCE.length()-1)
				tone += (random > CHANCE[CHANCE.length() - a_index])
		tone -= 7*((tone>upper) - (tone<lower))
		ladder[barnumber][a_index] := tone
		BArtones[barnumber][a_index] := freq_1[ladder_1[tone]]
		}
	barnumber++
	}


}

/*
	;REPEAT THEME
	
	if (random = 1) and (barnumber > 4)
	{
		
		loop 3
		{
		BArs[barnumber] := BArs[a_index]
		ladder[barnumber] := ladder[a_index]
		BArtones[barnumber] := BArtones[a_index]
		barnumber++
		}
	Tone := BArtones[barnumber-1][bartontes[barnumber-1].length()]
	}
	
	; END OF THEME REPEATER



	;REPEAT PREVIOUS THREE MEASURES WITH INCREASED TONE
	
	if (random = 2) and (barnumber > 4)
	{
	random, random, 0,1
	q := 1 - 2*random
	random, random, 2, 4
		loop % random
		{
			loop 2
			{
			BArs[barnumber] := BArs[barnumber - 2]
			BArtones[barnumber] := [0,0]
			Ladder[barnumber] := [0,0]

				loop % BArs[barnumber].length()
				{
				Ladder[barnumber][a_index] := ladder[barnumber-2][a_index] + q
				BArtones[barnumber][a_index] := freq_1[ladder_1[ladder[barnumber-2][a_index]+q+35]]
				}

			barnumber++
			}
		}

	Chance := CHances[Ladder[barnumber-1][ladder[barnumber-1].length()]] 
	Jumps := JUmpss[Ladder[barnumber-1][ladder[barnumber-1].length()]] 
	}
	; END OF MEASURE REPEATER
*/


	random, random, 1, Barchances[Barchances.length()]
	BArs[barnumber] := 0

		loop % (Barchances.length() -1) ; kies de maatsoort 
		BArs[barnumber] += (random > Barchances[Barchances.length() - a_index])

	BArs[barnumber] := BArtypes[BArs[barnumber]]




; GENERATE TONES

BArtones[barnumber] := [0,0]
Ladder[barnumber] := [0,0]

loop % BArs[barnumber].length()
{
CHANCE := CHANCES[mod(tone,7)+1]
	random, random, 1, CHANCE[CHANCE.length()] 
	tone -= 7

		loop % (CHANCE.length()-1)
		tone += (random > CHANCE[CHANCE.length() - a_index])


tone -= 7*((tone>upper) - (tone<lower))


ladder[barnumber][a_index] := tone

BArtones[barnumber][a_index] := freq_1[ladder_1[tone]]
}
}

;PLAY MEASURES

;goto KWINTMODULATOR
s:=0
loop 100
{
barnumber := a_index

	;PLAY NOTES

	loop % BArs[barnumber].length()
	{
	soundbeep BArtones[barnumber][a_index], (6/7) * 450 * BArs[barnumber][a_index]
	sleep (1/7) * 450  * BArs[barnumber][a_index]
	;q := ladder[barnumber][a_index]
	;r := BArs[barnumber][a_index]
	;s++
	;iniwrite, %q%, C:\Users\henk\Desktop\a.ini, %s%, tone
	;iniwrite, %r%, C:\Users\henk\Desktop\a.ini, %s%, length
	
	}

}
return


;speedchanger
/*
speed := -3
loop 3
{
tonecount:=0
tonecount2 := 0
speed += 1
changer := 2**speed
msgbox
loop 4
{
tonecount += 1

loop % BArs[a_index].length()
{
tonecount2 += 1
soundbeep freq[Ladder[tonecount2]], (((6/7) * 450 * BArs[tonecount][a_index]) * changer)
sleep (((1/7) * 500  * BArs[tonecount][a_index]) * changer)
}
}
}
*/



KWINTMODULATOR:

; Kwintmodulator
toneplus := -1
	loop 5
	{
	toneplus := a_index -1
		loop 2
		{
		barnumber := a_index
			loop % BArs[barnumber].length()
			{
			soundbeep freq_1[ladder_1[ladder[barnumber][a_index]+toneplus+33]], (6/7) * 450 * BArs[barnumber][a_index]
			sleep (1/7) * 500  * BArs[barnumber][a_index]
			}
		}
	}









^5::
reload
return
Last edited by florisvos on 08 Jun 2016, 14:41, edited 1 time in total.
User avatar
Xtra
Posts: 1833
Joined: 02 Oct 2015, 12:15

Re: Generating MIDI files

07 Jun 2016, 08:13

Example:

Code: Select all

#NoEnv
#SingleInstance, Force
SetWorkingDir, %A_WorkingDir%

; Close Encounters of the Third Kind Example:
Sample=
(Join`r`n
0, 0, Header, 1, 2, 480
1, 0, Start_track
1, 0, Title_t, "Close Encounters"
1, 0, Text_t, "Sample for MIDIcsv Distribution"
1, 0, Copyright_t, "This file is in the public domain"
1, 0, Time_signature, 4, 2, 24, 8
1, 0, Tempo, 500000
1, 0, End_track
2, 0, Start_track
2, 0, Instrument_name_t, "Church Organ"
2, 0, Program_c, 1, 19
2, 0, Note_on_c, 1, 79, 81
2, 960, Note_off_c, 1, 79, 0
2, 960, Note_on_c, 1, 81, 81
2, 1920, Note_off_c, 1, 81, 0
2, 1920, Note_on_c, 1, 77, 81
2, 2880, Note_off_c, 1, 77, 0
2, 2880, Note_on_c, 1, 65, 81
2, 3840, Note_off_c, 1, 65, 0
2, 3840, Note_on_c, 1, 72, 81
2, 4800, Note_off_c, 1, 72, 0
2, 4800, End_track
0, 0, End_of_file
)

FileAppend, %Sample%, Sample.csv


; Note: requires Csvmidi.exe in the working directory:
;                 csvmidi [ -u -v -x -z ] [ infile [ outfile ] ]
Run, %ComSpec% /c Csvmidi Sample.csv Sample.midi, %A_WorkingDir%, Hide

; check your folder for the created file:  sample.midi
florisvos
Posts: 20
Joined: 15 Apr 2016, 06:26
Facebook: https://www.facebook.com/floris.vos.77

Re: Generating MIDI files

08 Jun 2016, 13:45

Thank you thank you thank you!!!!!!!!!!!!!
Means a lot to me :)

Still gotta change my script to create proper CSV files that can be made into midi's, but at least now I know I WILL be able to convert it once I'm done :D
florisvos
Posts: 20
Joined: 15 Apr 2016, 06:26
Facebook: https://www.facebook.com/floris.vos.77

Re: Generating MIDI files [SOLVED]

08 Jun 2016, 14:43

Yep! Totally works!
Listening to some pretty awesome Organ music at the moment ;) Still got some bugs in my script to fix (i think i'm using an old version by accident), and then a whoooole lot of stuff to add now that I can make MIDI's, I'm really happy.

Return to “Ask For Help”

Who is online

Users browsing this forum: itsnotaron, mikeyww, tatagi and 23 guests