Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Random Music Player
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
charlie56




PostPosted: Sat Apr 09, 2005 2:25 pm   Post subject: Random Music Player

I was wondering if it is possible to have in procedure form a random music player. So im guess in the procedure you have to make a playlist out of all the midi files, abd then make it choose a random one to play and then when that ones finished it goes to another randomly chosen song. I would also just like to say that compsci.ca is by far the best turing resourse on the net and that you guys have great responose time with any question.
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Sat Apr 09, 2005 4:06 pm   Post subject: (No subject)

Right you are (on all your statements Laughing). You'll need:

Rand.Int()
Music.PlayFileReturn()
(better than .PlayFile)

Music.PlayFileStop
procedure()
function()


I'd suggest you look into arrays for this one, sepecifically flexible ones. Think about looking at a directory, writing down all the names of files than hold music (that OOT can play) one pieces of paper, putting them in a hat, and then drawing them out one after another. This of course raises the question of whether you want to have the files removed from the list after being played once or not...
charlie56




PostPosted: Sat Apr 09, 2005 5:05 pm   Post subject: (No subject)

well i think the idea of removing them from the list would be perfect because i plan on having enuf songs that u couldnt possibly play long enuf to run out of music and then it would be better too cuz then you wouldnt hear the same song multiple times(which with midi's can really start to get annoying).
charlie56




PostPosted: Sun Apr 10, 2005 1:18 am   Post subject: (No subject)

ive read up on flexible arrays read the tut in the tutorials section and this is wut i have, its a mess it started off fine then since it wasnt working i kept playing around with it to try to get it to work and now i dont no wut im doing lol. It all works fine it opens up displays welcome starts a song then displays test(which btw is only there so i could tell whether it kept going after running it)but when the song stops another doesnt start.anyways could someone maybe tell me wut is rong with this. and this is goin to be background music for a game im working on so it cant just be in a loop cuz the game needs to keep going.

code:

%Random Music Player
var playlist : flexible array 1 .. 5 of int
var remove, key, num : int

remove:=1
playlist (1) := 1
playlist (2) := 2
playlist (3) := 3
playlist (4) := 4
playlist (5) := 5

proc music
    for i : remove + 1 .. upper (playlist)
        put upper (playlist)
        randint(remove,1,5)
        remove:=playlist(remove)
        playlist (i - 1) := playlist (i)
        if remove = 1 then
            Music.PlayFileReturn ("final.mid")
        elsif remove = 2 then
            Music.PlayFileReturn ("mario.mid")
        elsif remove = 3 then
            Music.PlayFileReturn ("busters.mid")
        elsif remove = 4 then
            Music.PlayFileReturn ("OEML-2499.mid")
        elsif remove = 5 then
            Music.PlayFileReturn ("you_spin_me_right_round.mid")
        end if
    end for
    new playlist, upper (playlist) - 1
end music


put "Welcome"
music
put "test"
Delos




PostPosted: Sun Apr 10, 2005 8:06 am   Post subject: (No subject)

I don't get why you're using a for loop there, but I'm betting that that's your problem. Also, your resizing of the array occurs outside the loop, so that's no use.
To make your life easier, randomize the order of the songs before you start playing them. Your array should be a lot smarter than simple numbers. Right now you have to compare redundant values to find out which song to play. Why not use an array of strings instead? Each value could be the name of a song. Then randomize that.
Play it the whole way through (you can use your for loop here), and if need be loop it at the end. This particular method won't require you to use a flexible array...though you could if you wanted...
Once you've gotten this working, look into Dir. commands so that you can specifiy a particular folder and dynamically create a playlist from songs that are within it. This way you won't have to hardwire the names of the songs...which will be so much more efficient.
Cervantes




PostPosted: Sun Apr 10, 2005 8:16 am   Post subject: (No subject)

Turing:

var playlist : flexible array 1 .. 0 of string

var currentlyPlaying := false

proc addMusic (directory : string)
    %check with Dir.Exists
    %use new playlest, upper (playlist) + 1
    %use Dir.Get (I think)
end addMusic

proc randomizPlaylist

end randomizPlaylist

proc playMusic
    loop
        for i : 1 .. upper (playlist)
            Music.PlayFile (playlist (i))
        end for
    end loop
end playMusic


Problem here is that while your music is playing, your program can't do anything else. If you use Music.PlayFileReturn, you'll need to find out how to determine whether a song is playing.

As this gets more complex, you'll want to look into making a flexible array of a record, so that you can store lots of information.
Turing:

var song : flexible array 1 .. 0 of
    record
        destination : string
        artist, title, album, genre, year : string
        trackNumber : int
        timesPlayed : int
    end record
Delos




PostPosted: Sun Apr 10, 2005 10:44 am   Post subject: (No subject)

Cervantes wrote:

If you use Music.PlayFileReturn, you'll need to find out how to determine whether a song is playing.


Well, if you want to be sure then just use a Music.PlayFileStop(), and anything that was playing will cease to. The most one can really do is to ensure files exist and perhaps set up a check to log when Music.PlayFileReturn() has been called...
charlie56




PostPosted: Sun Apr 10, 2005 11:03 am   Post subject: (No subject)

what im thinking might be easier to do then all this is just have the music playing code in a seperate file then when u run the game it will open the other program and ill have it hide and then it can just play music wihile the game is going with no interfercnes or anything. Ya i read the flexible array tuts and i think it might be a little above me.

EDIT

code:

var playlist : flexible array 1 .. 5 of string
var dir,random:string
var currentlyPlaying := false
var direc:int

proc addMusic (directory : string)
    if Dir.Exists (directory) then %check with Dir.Exists
    new playlist, upper(playlist)+1%use new playlest, upper (playlist) + 1
    random:=Dir.Get (direc)
    put direc
    else
    put "Directory is incorrect"
        end if
    end addMusic

    proc randomizPlaylist
    for i : direc+1..upper (playlist)
    randint(direc,1,5)
    new playlist, upper(playlist)-1
    end for
    end randomizPlaylist

    proc playMusic
        loop
            for i : 1 .. upper (playlist)
                Music.PlayFile (playlist (i))
            end for
        end loop
    end playMusic
   
dir:="Music"
    direc:=Dir.Open("Music")
    addMusic(dir)
    randomizPlaylist
playMusic


i no a lot of this isnt right. i think i might just scrap the music idea for my game its not needed nayways just wanted to make it nice. but if any1 could help some more that would be great. and again ive meesed around with it so much that now i dont no wut is happening
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: