How to get computer to play my songs written in Visual Basic 6.0?
March 20, 2004 12:10 PM   Subscribe

Musical notes in Visual Basic 6.0: I wrote a program that writes random songs, and I'd like it to be able to play them, so I don't have to plunk them out on my bass to know what they sound like.

I looked into the Multimedia control, and as far as I can tell it doesn't seem to do what I want. Ideally, I'd like access to the sounds in my sound card, but I'd be happy with plain old-school beeps.
posted by alex_reno to Computers & Internet (12 answers total)
 
In what format does your program generate these songs? If you can write to MIDI format, then you can use any number of pre-existing players. Something like this might help...

More detail about your program would probably be useful.
posted by Galvatron at 12:23 PM on March 20, 2004


Currently, it just knows the names of the notes and how many beats to hold them. It doesn't write them to file in any particular format. Screenie.
posted by alex_reno at 12:43 PM on March 20, 2004


In order to play the notes, you'll need to feed them into some kind of software that understands what a 'note' is. You might want to write some kind of save-to-MIDI functionality.
posted by Jairus at 1:35 PM on March 20, 2004


just a nit, but a random collection of notes does not a song make. thank you. you may now ban my sorry ass.
posted by quonsar at 4:59 PM on March 20, 2004


Dear high priest of quons, I believe he is seeking to listen to them to determine if they've got any song-like bits worthy of keeping, perhaps to help him refine the note-generating ability of said software. Maybe after many iterations of refinement, he might have himself something that can produce actual worthwhile songs.
posted by beth at 5:20 PM on March 20, 2004


Does Zel offer you a path to MIDI zen? If your program can write out the musical notes in the Zel language, Zel can play them.
posted by dhartung at 9:46 PM on March 20, 2004


dhartung, Zel sounds like it might do the trick, thanks, I'll check it out.

Just to confirm, though, Visual Basic offers no innate ability to produce a tone of a certain pitch and length? I searched and couldn't find it.
posted by alex_reno at 1:41 AM on March 21, 2004


http://www.officecomputertraining.com/vbtutorial/tutpages/page41.asp - Unfortunately, VB has only one intrinsic statement which will play sound. The Beep statement requires no parameters and will play the default system sound, usually that annoying 'ding'.

writing midi files isn't the easiest thing in the world - you'd be better finding a library to use or writing a simpler format that something can translate (zel sounds good).
posted by andrew cooke at 4:46 AM on March 21, 2004


Dear high priest of quons, I believe he is seeking to listen to them to determine if they've got any song-like bits worthy of keeping, perhaps to help him refine the note-generating ability of said software. Maybe after many iterations of refinement, he might have himself something that can produce actual worthwhile songs.

Absolutely....I often use the "random pattern" function on Reason to see what the program comes up with. Randomness is interesting when it comes down to repetitive loops.
posted by SpaceCadet at 9:24 AM on March 21, 2004


Andrew, thank you for the confirmation. That was the only thing I found, too.

Longish description of program follows - don't mind me, I feel somewhat chatty today.

FWIW, the note choice isn't fully random. Each possible interval has a weight, essentially a number of lottery balls. The program determines the notes that it could choose that are in key, then makes a roll based on the weights each interval has been given. As currently set up, it is more likely to pick semitones and tritones if they are available, because that's the sort of music I like.

After listening to what it comes up with, if I like or dislike a particular part, I can reward or punish it, which will increase (or decrease) the weights used for the intervals that were used in the part, making them more (or less) likely to be chosen in the future.

Also, it is aware of the time signature and is more likely to hold notes longer if the number of beats per bar is higher. The not yet implemented complexity will modify this as well.

Eventually, I intend to add a library of all possible 3 to 5 (or more) interval sequences, ie riffs or melodies, which can then be rewarded or punished with the rest. After a non-trivial amount of time spent training it, it should be able to come up with songs similar to the ones I write.

As well, some more basic things like accidentals, modulation, and notes smaller than a quarter might make it in there as well.
posted by alex_reno at 12:37 PM on March 21, 2004


OK, there is an answer here, but I'm not sure of how proficient a programmer you are. Microsoft provides several audio APIs for dealing with sound.
  • MCI (Media Control Interface) is mainly for controlling devices, starting CD drives, media players, etc.
  • Wave form Audio These API's are mainly with dealing with audio waveforms and playing and transforming the waveforms before releasing to a specific device.
  • And finally, MIDI API This API provides what I think is the clearest path to accomplishing what you are trying to accomplish, basically playing musical notes through your speakers, modulating, and extending them.
And to your question, Visual Basic does not natively support sound functions (with the exception of Beep - which is a can of worms anyway).

Someone has translated the MIDI API into Visual Basic (look halfway down the page. Which I think accomplishes what you are looking for.
posted by patrickje at 10:42 AM on March 22, 2004


Patrick, that last link looks to be exactly what I'm looking for. Thank you so much.
posted by alex_reno at 11:42 AM on March 22, 2004


« Older What causes house to "beat" in the wind?   |   Free Journalism, online? Newer »
This thread is closed to new comments.