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

Username:   Password: 
 RegisterRegister   
 Music Player Help
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Inuspal




PostPosted: Fri Jan 02, 2009 11:38 pm   Post subject: Music Player Help

I'm currently doing a culminating task for my grade 10 science course, I'm making a music player with Turing. I did some searching on the forum and got some neat ideas.
I tried doing a file search and I saw some hints for it in the forum which I tried using, but my problem is, I can't get my program to actually search for file names with a .mp3/.wav/.midi extension, and then display them on the program. I realize the usage of arrays is needed but I'm horrible with those (I've tried learning them several times before, I barely understand the concept).

could someone please help me out with this?
Sponsor
Sponsor
Sponsor
sponsor
The_Bean




PostPosted: Fri Jan 02, 2009 11:58 pm   Post subject: Re: Music Player Help

Look up Dir.Open and Dir.Get in the turing help files (F10).
From that use some string manipulation to see if they are the correct file type.
Use a flexible array to store them if they are the correct format.
petree08




PostPosted: Sat Jan 03, 2009 9:50 am   Post subject: RE:Music Player Help

If your searching method is to include subfolders then you might want to have a look at recursion,
B-Man 31




PostPosted: Sat Jan 03, 2009 1:11 pm   Post subject: Re: Music Player Help

i tried making a music player, and i got the player to open and play files but you cant do much more than that. you cant ghange volume and only thing you could maybe add is a play list and play/stop buttons.
Inuspal




PostPosted: Sun Jan 04, 2009 10:32 am   Post subject: RE:Music Player Help

Thanks for the help, and now I got the file names to come up on the program, but my problems now are:

I got some .jpg files (album artwork) and I'm not sure how to limit it to just .mp3, .wav, and .midi files?

Also, for the user to select the song, do I need to use GUI? If so, how can I make each and every song clickable?
andrew.




PostPosted: Sun Jan 04, 2009 11:51 am   Post subject: RE:Music Player Help

To limit it to mp3, wav, and midi, just check each filename to see if the ending is .mp3, .wav, etc.

No, you don't need to use the GUI. I highly recommend not using the GUI. Instead read up on Mouse.Where.

Off-topic: In Java, we're using some source code someone already came up with to read wav files into an array to be played. We are able to reverse it, add echoes, speed it up, slow it down, etc. I suppose we can change the volume. Do you think there is a way to load wav files into Turing into an array? I highly doubt it, but you never know.
Euphoracle




PostPosted: Sun Jan 04, 2009 11:56 am   Post subject: RE:Music Player Help

No there isn't, it provides no methods of doing so. Turing can only use its built-in procedures for playing sound, iirc.
Inuspal




PostPosted: Sun Jan 04, 2009 1:19 pm   Post subject: RE:Music Player Help

I don't understand how to get Turing to check the filename endings...can someone please expand on that?
Sponsor
Sponsor
Sponsor
sponsor
The_Bean




PostPosted: Sun Jan 04, 2009 1:50 pm   Post subject: Re: Music Player Help

You'll need to check the last 4 or 5 characters to see if they're '.mp3' or '.wav' or '.midi'.
Since every name will have a different length you'll need to make it in relation to the total length of the string. length()
To check certain characters in a string you can call the string with parameters like an array but with a range.
Turing:

var name : string := "Barenaked Ladies - Barenaked for the Holidays - 03 - I Saw Three Ships.mp3"
put name (1 .. 5)

Now to make it in relation to the max length of the string
Turing:

var name : string := "Barenaked Ladies - Barenaked for the Holidays - 03 - I Saw Three Ships.mp3"
put name (length (name) - 3 .. length (name))
Inuspal




PostPosted: Sun Jan 04, 2009 2:14 pm   Post subject: Re: Music Player Help

Oh thanks for the tip
I tried it out, this is what it looks like

Turing:

DirID := Dir.Open (filefolder)

streamNumber := Dir.Open (filefolder)
assert streamNumber > 0
loop
    fileName := Dir.Get (streamNumber)
    delay (50)
    exit when fileName = ""
    if (length (fileName) - 4) = ".mp3" then
        put fileName
    end if
    if (length (fileName) - 4) = ".wav" then
        put fileName
    end if
    if (length (fileName) - 5) = ".midi" then
        put fileName
    end if
end loop
Dir.Close (streamNumber)


but I'm getting errors... :/ it's telling me "Operands of comparison and operators must be the same type"
The_Bean




PostPosted: Sun Jan 04, 2009 2:37 pm   Post subject: Re: Music Player Help

(length (fileName) - 4) is just a number and ".mp3" is a string.
Look at my post again and see how it works.
Inuspal




PostPosted: Sun Jan 04, 2009 2:58 pm   Post subject: Re: Music Player Help

This is rather confusing for me, I apologize for sounding like a total n00b, I suck at Turing, but
I'm not trying to do the same thing you did in your post though... I just want my program to display all the files that end in .mp3/.wav/.midi
every time I try it and change parts of it, I get a different error
here's what I just tried recently:

Turing:

DirID := Dir.Open (filefolder)

streamNumber := Dir.Open (filefolder)
assert streamNumber > 0
loop
    fileName := Dir.Get (streamNumber)
    if fileName (length (fileName) - 4 .. length (fileName)) = ".mp3" then
        put fileName
    end if
    if fileName (length (fileName) - 4 .. length (fileName)) = ".wav" then
        put fileName
    end if
    if fileName (length (fileName) - 5 .. length (fileName)) = ".midi" then
        put fileName
    end if
    delay (50)
    exit when fileName = ""

end loop
Dir.Close (streamNumber)
The_Bean




PostPosted: Sun Jan 04, 2009 3:39 pm   Post subject: Re: Music Player Help

I know what you're trying to do, I was just showing how to get the last characters to check.
1) Why are you using Dir.Open() twice with the same folder?
2) fileName (length (fileName) - 4 .. length (fileName)) --- will give more characters than you want, you only want the last four so its like starting counting with 0 you will end with 1 extra than you want (subtract only 3)
3) Move the exit when to above the if statement
4) The first files in a windows folder are "." and ".." so they have less than 4 and will get a negative string subscript. So you need to make sure that the name length of file is greater than 4 first.
Inuspal




PostPosted: Sun Jan 04, 2009 5:22 pm   Post subject: RE:Music Player Help

Yaay it worked! Thankyou very much, The_Bean, you're very helpful =D

...And now I've stumbled upon more problems @_@ does it ever end?

1) I can't get the darn scrollbar to work

2) I have no idea how to make it so that I can select song names with a mouse and play them, since it's recommended I don't use GUI like huh D:
Insectoid




PostPosted: Sun Jan 04, 2009 8:09 pm   Post subject: RE:Music Player Help

Make your own buttons with Draw.Box and Mouse.Where using ordinary collision detection. If the user clicks the button with this name on it, play that music file. elsif he clicks that button, do that one. If he clicks 'stop', Music.PlayFileStop. That easy. Scroll bar might be a bit complicated.
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 2  [ 21 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: