Random Midi Player - Gramp v0.2

Synthesia is a living project. You can help by sharing your ideas.
Search the forum before posting your idea. :D

No explicit, hateful, or hurtful language. Nothing illegal.
Lemo
Posts: 313

Post by Lemo »

Okay, as planned I have merged those three functions in a single program.
There is a bunch of optimizations, especially around the regular expressions (mostly thanks to this very handy website), so now it won't miss a single midi :].
I decided to make a real user interface (which may remind you something :p) for some additional features, and now the program got a name: GRAMP! (also know as Global Random Midi Player :mrgreen: )

Image

This will be released quite soon, as most functions are already working, and in the mean time I'll post some of the scripts here.
The idea is to be able to add midi sources as "plugins", that everyone can write to expand the range of GRAMP!
So here is what the three first sources scripts look like :

Local.ahk
Spoiler:

Code: Select all

localGet(){

Loop
{


;Retrieve watched folders from Synthesia config

totalfolders = 0
watchedfolders=folders.xml
Loop, read, %watchedfolders%
{
        totalfolders += 1
}
totalfolders -= 1
Random, selectfolder, 2, %totalfolders%
FileReadLine, folderline, %watchedfolders%, selectfolder
StringSplit, folder, folderline , "


;Get the number of files in choosen directory

totalfiles = 0
Loop, %folder4%\*.mid, 0, %folder6%
{
        totalfiles += 1
}


;Select a random file from directory

Random, selectfile, 0, %totalfiles%
Loop, %folder4%\*.mid, 1, %folder6%
{
       	IfEqual, A_Index, %selectfile%, Setenv, file, %A_LoopFileFullPath%
}


;Send result if there's a file

StringLen, check, file
If check > 0
{
	return %file%
}


}

}
Mutopia.ahk
Spoiler:

Code: Select all

mutopiaGet(){

Loop 
{


;Choose a page to download a song from

Random, rand, 1, 2000
UrlDownloadToFile, http://www.mutopiaproject.org/cgibin/piece-info.cgi?id=%rand%, page.htm
FileRead, Haystack, page.htm
FileDelete, page.htm


;Retrieve the file link

RegExMatch(Haystack,"file.*\.(midi|mid)",fileplus)
StringSplit, filecrop, fileplus, "
StringTrimLeft, filetrim, filecrop2, 2
file=http://www.mutopiaproject.org%filetrim%


;Send result if there's a file

StringLen, check, filetrim
if (check > 0)
{
	return %file%
}


}

}
8notes.ahk
Spoiler:

Code: Select all

8notesGet(){

Loop 
{

;Choose a page to download a song from

Random, rand, 300, 13000
UrlDownloadToFile, http://www.8notes.com/scores/%rand%.asp?ftype=midi, page.htm
FileRead, Haystack, page.htm
FileDelete, page.htm


;Retrieve the file link

RegExMatch(Haystack,"http?:\/\/.*.(midi|mid)",file)


;Send result if there's a file

RegExMatch(Haystack,"midi_on",midi)
StringLen, check, midi
StringLen, check, file
if (midi >0 and check > 0)
{
	return %file%
}


}

}
The main application calls a function in the external script, that returns a midi file with its path.
So if you want to join, feel free to write a plugin for your favorite website if you like :roll: .
I believe it's better to use websites with an id for each song for now, as they're easier to randomize, and usually have a specific info page for each song, with some additional ressources that GRAMP! is probably going to use later.

The app is coming, stay tuned!
Stuff & experiments for Synthesia: Gramp v0.2SkinboxFireSynthVideoWebradio
User avatar
DC64
Posts: 830

Post by DC64 »

I love the progress you are making.
Cant wait for the next thing.
"And now for something completely different."
Nicholas
Posts: 13135

Post by Nicholas »

This looks neat. I want to mess around with it when it's ready.
aria1121
Posts: 1505

Post by aria1121 »

XP install folder: "%SYSTEMDRIVE%\Program Files\Synthesia\synthesia.exe"
Vista/7 install folder: "%SYSTEMDRIVE%\Program Files (x86)\Synthesia\synthesia.exe"

Your script doesn't check this.
Lemo
Posts: 313

Post by Lemo »

Yeah thanks! Apparently you just have to use %ProgramFiles%\Synthesia\synthesia.exe for autokey ^^
Btw those scripts have changed a bit in the meantime, to include the "id" for my lil log file.
I also added another source, http://www.midicenter.com, to add a bit of pop fantasy :]
Stuff & experiments for Synthesia: Gramp v0.2SkinboxFireSynthVideoWebradio
Lemo
Posts: 313

Post by Lemo »

Gramp has arrived, see the first post ;)
That's mainly some ramblings of a non-developer, as Rich would say
So please report bugs if something doesn't work as expected :p
Stuff & experiments for Synthesia: Gramp v0.2SkinboxFireSynthVideoWebradio
aria1121
Posts: 1505

Post by aria1121 »

For real, how in the world did you compress it so my compression ratio of 7Zip is like 3479% ???
Anyway, it's supercool and worked fine for me on Win7.

Finally something to mess around MIDI sites with without doin' it self!
aria1121
Posts: 1505

Post by aria1121 »

After messing some more it looks like it freezes some after you scrub the volumebar a lot. And is it supposed to return an empty MsgBox after leaving Synthesia with the Play-button in GRaMP! ?
Lemo
Posts: 313

Post by Lemo »

Oups looks like it forgot to remove a debugging box :p
This one was there to check the score array from Synthesia
It's re-uploaded without it, should be better
Dunno what's up with that volume bar though
Thanks for trying Gramp ^^
Stuff & experiments for Synthesia: Gramp v0.2SkinboxFireSynthVideoWebradio
User avatar
DC64
Posts: 830

Post by DC64 »

I love it! Is there any way I can be involved?

Is there a maximum amount of sources that will be saved or is that infinite?
What are the numbers for next to the volume?
What is the green bar?
Is Local the folders that Synthesia watches?
Maby it can play from a certian directory file.
"And now for something completely different."
Lemo
Posts: 313

Post by Lemo »

DC64 wrote:I love it! Is there any way I can be involved?
Is there a maximum amount of sources that will be saved or is that infinite?
Currently the number of sources is mostly limited to the number of good midi portals I know. But I guess that could be as infinite as the web can be ;) .

As I said in a previous message, you can be involved by writing a plugin for your favourite midi website (see the files in the sources folder), or if you don't know how to script in autohotkey,
you can still send me the links (I already read all that thread). Each song gotta have its own page, with an ID to find it, for example:
"http://www.mutopiaproject.org/cgibin/pi ... .cgi?[b]id[/b]=1108"
DC64 wrote:What are the numbers for next to the volume?
What is the green bar?
Please do us a favour and read everything twice :roll:
As mentioned, the grey box next to the volume displays the size of the midi (in octets). As I can't retrieve the length yet, that's still a way to judge the complexity of a song, as it's size is directly proportional to the number of notes. When I'll have the length, I'll be able to divide it from the size or notes, to display its complexity with a colour code in that same box.
Concerning the green bar, that's obviously a time slider, but as I also explained it will be activated in the next version.
DC64 wrote:Is Local the folders that Synthesia watches?
Maby it can play from a certian directory file.
If people want more control I think I can make some room for custom directories.
For now I'm retrieving the watched folders indeed.
Stuff & experiments for Synthesia: Gramp v0.2SkinboxFireSynthVideoWebradio
Lemo
Posts: 313

Post by Lemo »

Just a little update.
I realized that the last tab was showing the old shortcuts.
The corrected archive is up, with those :
F1: Save - F2:Play - F3:Skip - F4:Exit
Btw you may also use F5 if you want to reload the thing for whatever reason.
Stuff & experiments for Synthesia: Gramp v0.2SkinboxFireSynthVideoWebradio
User avatar
DC64
Posts: 830

Post by DC64 »

Not shure if this might work but its my first "real code", I tried. (probably not correct though) :roll:
Spoiler:

Code: Select all

mididbGet(){

Loop 
{


;Choose a page to download a song from

Random, rand, 1, 2000
UrlDownloadToFile, http://www.mididb.org/cgibin/piece-info.cgi?id=%rand%, page.htm
FileRead, Haystack, page.htm
FileDelete, page.htm


;Retrieve the file link

RegExMatch(Haystack,"file.*\.(midi|mid)",fileplus)
StringSplit, filecrop, fileplus, "
StringTrimLeft, filetrim, filecrop2, 2
file=http://www.mididb.org%filetrim%


;Send result if there's a file

StringLen, check, filetrim
if (check > 0)
{
   return %file%
}


}

}
http://www.mididb.com
"And now for something completely different."
Lemo
Posts: 313

Post by Lemo »

Well that's a nice try
But that ain't gonna work unfortunately :roll:

You took that code from the Mutopia function, but Mididb doesn't have that ID system I was talking about.
Just look at the URL when you are on their website:
Mutopia: http://www.mutopiaproject.org/cgibin/piece-info.cgi?id=1108
Mididb: http://themes.mididatabase.com/movies/
Those two are really different

Let's check the first two lines in the loop:
Random, rand, 1, 2000 > The script chooses a number between 1 and 2000, for example rand=300
UrlDownloadToFile, http://www.mididb.org/cgibin/piece-info.cgi?id=%rand%, page.htm > It tries to retrieve the page with that URL
http://www.mididb.com/cgibin/piece-info.cgi?id=300
->And of course the page won't exist

I could do random scripts based on other things that a random ID, but for the moment it's more simple this way.

After those lines there is a "RegExMatch", which is a regular expression you have to adapt for each site, but that's already a lot more complex than the first two lines.

If you want to try stuff for yourself, just install Autohotkey (and read a bit of the documentation). You will see what works and what doesn't. ;)
Stuff & experiments for Synthesia: Gramp v0.2SkinboxFireSynthVideoWebradio
Lemo
Posts: 313

Post by Lemo »

Hey I found some homework for you DC64 (or anyone else who wants to be involved), if you still want to play around with code
:arrow: http://ichigos.com
This one is for anime & game music fans out there.
Each section has its own id, but this site is a bit more tricky because you can have several songs by anime/game.
So you have to find a random "sheet" url (1 to 500), then find a random song in that page.
Good luck :)

PS: Here is a simplified standalone 8notes script to start with:

Code: Select all

Loop 
{

    ;Choose a page to download a song from

    Random, rand, 300, 13000
    UrlDownloadToFile, http://www.8notes.com/scores/%rand%.asp?ftype=midi, page.htm
    FileRead, Haystack, page.htm
    FileDelete, page.htm


    ;Retrieve the file link
	
    RegExMatch(Haystack,"http?:\/\/.*.(midi|mid)",fileplus)
    filepath=%fileplus%|http://www.8notes.com/scores/%rand%.asp?ftype=midi

    ;Send result if there's a file

    StringLen, check, fileplus
    if (check > 0)
	{
	msgbox, %filepath%
	}
    else
	{
	msgbox, No url with that id: %rand%
	}

}
Stuff & experiments for Synthesia: Gramp v0.2SkinboxFireSynthVideoWebradio
User avatar
DC64
Posts: 830

Post by DC64 »

There are some more from here by Seabass
http://sebastianwolff.info/ (@ Lemo, the link reminded me of him)
"And now for something completely different."
Lemo
Posts: 313

Post by Lemo »

Hum did I tell you about IDs already? -_-'
Stuff & experiments for Synthesia: Gramp v0.2SkinboxFireSynthVideoWebradio
User avatar
DC64
Posts: 830

Post by DC64 »

:|oops.
"And now for something completely different."
Lemo
Posts: 313

Post by Lemo »

Yay ^-^

Image
Stuff & experiments for Synthesia: Gramp v0.2SkinboxFireSynthVideoWebradio
User avatar
DC64
Posts: 830

Post by DC64 »

Your first home-made Soundfont?
"And now for something completely different."
Post Reply