Jump to content



Photo
* * * * * 1 votes

Adding music (mp3's) to a table?


  • Please log in to reply
32 replies to this topic

#21 mrjcrane

mrjcrane

    Pinball Fan

  • Members
  • PipPipPipPip
  • 545 posts
  • Location:Northern California

  • Flag: United States of America

  • Favorite Pinball: Monster Bash

Posted 18 January 2023 - 07:59 AM

Side question on this topic, is there an additional parameter I can throw on to the tail end of PlayMusic parameter to control the volume of any of the music track? Thanks in advance

 

PARTIAL EXAMPLE (PlayMusic VPX Command)

SUB MusicOn
    IF jukebox = 0 THEN
       EndMusic
    END IF

    IF jukebox = 1 THEN
'***START OF ORIGINAL 15 RANDOM TRACKS
    Dim musicEnd
    Dim z
    z = INT(15 * RND(1) )
    Select Case z
        Case 0:PlayMusic "PBR1.mp3"
        Case 1:PlayMusic "PBR2.mp3"
        Case 2:PlayMusic "PBR3.mp3"



#22 wiesshund

wiesshund

    VPF Legend

  • Members
  • PipPipPipPipPipPipPip
  • 11,859 posts

  • Flag: United States of America

  • Favorite Pinball: How many can i have?

Posted 18 January 2023 - 07:04 PM

No, playmusic pretty much just starts file and stops file
all playmusic does is ask windows to call mediaplayer.ocx and play the given file


If you feel the need to empty your wallet in my direction, i don't have any way to receive it anyways

Spend it on Hookers and Blow


#23 mrjcrane

mrjcrane

    Pinball Fan

  • Members
  • PipPipPipPip
  • 545 posts
  • Location:Northern California

  • Flag: United States of America

  • Favorite Pinball: Monster Bash

Posted 18 January 2023 - 09:09 PM

No, playmusic pretty much just starts file and stops file
all playmusic does is ask windows to call mediaplayer.ocx and play the given file

Thanks Wies !



#24 mrjcrane

mrjcrane

    Pinball Fan

  • Members
  • PipPipPipPip
  • 545 posts
  • Location:Northern California

  • Flag: United States of America

  • Favorite Pinball: Monster Bash

Posted 19 January 2023 - 02:00 AM

JoGrad, I like this mod, is there a way I can tweak it just a little so that it can read the Song File sequentially based on file name ... so 

Track01.ogg

Track02.ogg

Track03.ogg

Track 04.ogg and so on in the music folder?

 

 

Easily Add Music To Any Table

 

Here's a function to add music to a table, you just need the directory name.  No need to number songs or call them out in the script.  Songs are played randomly.  You can add new songs to the directory and they will be picked up automatically.

Once the table script is updated and the table started.  A song can be started or can be switched to next song by clicking the Right Magna key.  The music can be stopped by clicking the Let Magna key

 

Here's the script, just paste it below any End Sub command.  Then change the text in red to the name of the directory that has your mp3 files (ogg files do not work).  It must be a child folder of the Visual Pinball\music folder (for example C:\Visual Pinball\Music\AltCountryWestern)

 

Sub MusicOn
    Dim FileSystemObject, folder, r, ct, file, musicPath, myMusicFolder
    myMusicFolder = "AltCountryWestern" ' the directory name where your mp3 files are storied, must be a subfolder of Visual Pinball\music
    Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
    musicPath = FileSystemObject.GetAbsolutePathName(".") ' get path to Visual Pinball\table
    musicPath = Left(musicPath, Len(musicPath) - 6) + "music\" 'get path to Visual Pinball\music
    Set folder = FileSystemObject.GetFolder(musicPath + myMusicFolder)
    Randomize
    r = INT(folder.Files.Count * Rnd + 1)
    ct=1
    For Each file in folder.Files 'get every file in myMusicFolder, for each one count it and see if the count matches the random number
        if ct = r Then  ' random file found
            if (LCase(Right(file,4))) = ".mp3" Then ' can only play mp3 files
               PlayMusic Mid(file, Len(musicPath) + 1, 1000) ' PlayMusic defaults to Visual Pinball\music\, need to get myMusicFolder\song name
            End If 
       End If
   ct = ct + 1
   Next
 End Sub
 
Sub Table1_MusicDone() 'may not be called Table1
    MusicOn
 End Sub
 
The only other thing you need to do is add the commands to catch the right and left Magna Keys in the KeyDown function.  Add the lines in red

Sub Table1_KeyDown(ByVal keycode) 'may not be called Table1
    If keycode = RightMagnaSave Then MusicOn
    If keycode = LeftMagnaSave Then EndMusic
 
MusicOn can also be put in the Table1_Init sub to start music when the table starts
 
Make sure you save your changed (File/Save)
 
 
 

 



#25 wiesshund

wiesshund

    VPF Legend

  • Members
  • PipPipPipPipPipPipPip
  • 11,859 posts

  • Flag: United States of America

  • Favorite Pinball: How many can i have?

Posted 19 January 2023 - 03:26 AM

 

JoGrad, I like this mod, is there a way I can tweak it just a little so that it can read the Song File sequentially based on file name ... so 

Track01.ogg

Track02.ogg

Track03.ogg

Track 04.ogg and so on in the music folder?

 

 

 

 
 

 

 

Dont put OGG in the music folder
Unless it is copywritten music that you cant distribute
(and i still would not put it in the music folder)

 

Put the OGG files in the table itself

play them with playsound

 

Do what ever routine you want to do to determine song number

then do like playsound "mysong"&value

 

And as an added bonus, you can now change the volume.

And if said sounds were non distributable, i still would not use music folder

I would just set up the table to play them, then delete the sounds from the table before uploading

And then just tell the users
You need to get such n such songs
You need to put them in OGG format, and give them these names
then import into the table's sound manager, and set to backglass

 

*SOME ASSEMBLY REQUIRED


If you feel the need to empty your wallet in my direction, i don't have any way to receive it anyways

Spend it on Hookers and Blow


#26 xenonph

xenonph

    I have Pinball Fever!

  • VIP
  • 4,116 posts
  • Location:Castle Rock, WA.

  • Flag: United States of America

  • Favorite Pinball: TRON Classic-Congo-Xenon-PINBOT-BOP-LOTR-A Real American Hero OPERATION PINBALL-Millionaire-Whirlwind-Krull-NFL-BlackKnight-FishTales

Contributor

Posted 19 January 2023 - 03:41 AM

If you import the music into Sound Manager, you will need to add Stop Sounds command, as they will no longer shut off automatically when another file is played.


CHECK OUT THIS TUTORIAL http://www.vpforums....howtopic=32515
TO USE DB2S BACKGLASS PROGRAM WITH DESKTOP TABLES ON 1 MONITOR
 

#27 wiesshund

wiesshund

    VPF Legend

  • Members
  • PipPipPipPipPipPipPip
  • 11,859 posts

  • Flag: United States of America

  • Favorite Pinball: How many can i have?

Posted 19 January 2023 - 04:40 AM

If you import the music into Sound Manager, you will need to add Stop Sounds command, as they will no longer shut off automatically when another file is played.

 

yes that is true

but on the upside, you can stop a sound, and then resume it later as well, from where it left off.


If you feel the need to empty your wallet in my direction, i don't have any way to receive it anyways

Spend it on Hookers and Blow


#28 xenonph

xenonph

    I have Pinball Fever!

  • VIP
  • 4,116 posts
  • Location:Castle Rock, WA.

  • Flag: United States of America

  • Favorite Pinball: TRON Classic-Congo-Xenon-PINBOT-BOP-LOTR-A Real American Hero OPERATION PINBALL-Millionaire-Whirlwind-Krull-NFL-BlackKnight-FishTales

Contributor

Posted 19 January 2023 - 04:50 AM

Yes alot more commands to work with when files are in the sound manager.


CHECK OUT THIS TUTORIAL http://www.vpforums....howtopic=32515
TO USE DB2S BACKGLASS PROGRAM WITH DESKTOP TABLES ON 1 MONITOR
 

#29 mrjcrane

mrjcrane

    Pinball Fan

  • Members
  • PipPipPipPip
  • 545 posts
  • Location:Northern California

  • Flag: United States of America

  • Favorite Pinball: Monster Bash

Posted 19 January 2023 - 10:57 PM

 

 

JoGrad, I like this mod, is there a way I can tweak it just a little so that it can read the Song File sequentially based on file name ... so 

Track01.ogg

Track02.ogg

Track03.ogg

Track 04.ogg and so on in the music folder?

 

 

 

 
 

 

 

Dont put OGG in the music folder
Unless it is copywritten music that you cant distribute
(and i still would not put it in the music folder)

 

Put the OGG files in the table itself

play them with playsound

 

Do what ever routine you want to do to determine song number

then do like playsound "mysong"&value

 

And as an added bonus, you can now change the volume.

And if said sounds were non distributable, i still would not use music folder

I would just set up the table to play them, then delete the sounds from the table before uploading

And then just tell the users
You need to get such n such songs
You need to put them in OGG format, and give them these names
then import into the table's sound manager, and set to backglass

 

*SOME ASSEMBLY REQUIRED

 

Just Clarifying 1)I would not be distributing copyrighted material inside the table or outside the table (I'm leaving it to end-users to locate the tracks they need). 2)I am building table infostructure to a table that points back out to external music folders. 3)I like using the .ogg extention, external to the VP sound library as .ogg is opensource and has good compression.

 

 

If you import the music into Sound Manager, you will need to add Stop Sounds command, as they will no longer shut off automatically when another file is played.

 

yes that is true

but on the upside, you can stop a sound, and then resume it later as well, from where it left off.

 

Thanks Wise and others. I am purposefully avoiding music import the Sound Manager Library (in order to keep the tables smaller in general), will not be attaching any copyrighted music internal or external to the table. I am only building out containers/folders for the the music to reference external to the table. I am leaving the actual music tracks to the end user to find on their own. I am just building out the the structure to handle Multiple External Folders under the \music folder in VPX.  I have a method & subroutine to stop music with the external PlayMusic command already built out. I do like the .ogg as it is open source.

 

So my goal is how do I do a read of music files in an external \music\table\folder1 kind of path when the number of tracks living in the target folder can be variable.



#30 wiesshund

wiesshund

    VPF Legend

  • Members
  • PipPipPipPipPipPipPip
  • 11,859 posts

  • Flag: United States of America

  • Favorite Pinball: How many can i have?

Posted 20 January 2023 - 01:29 AM

 

Thanks Wise and others. I am purposefully avoiding music import the Sound Manager Library (in order to keep the tables smaller in general), will not be attaching any copyrighted music internal or external to the table. I am only building out containers/folders for the the music to reference external to the table. I am leaving the actual music tracks to the end user to find on their own. I am just building out the the structure to handle Multiple External Folders under the \music folder in VPX.  I have a method & subroutine to stop music with the external PlayMusic command already built out. I do like the .ogg as it is open source.

 

 

So my goal is how do I do a read of music files in an external \music\table\folder1 kind of path when the number of tracks living in the target folder can be variable.

 

 

You do not need to include the music
you simple tell the user, you need to get XX songs
convert them to OGG format
Name them as such
Import into the table's sound manager
Tag as backglass
Save table

 

But as to your last question

 

If music is in vpx\music\wondertable

playmusic "wondertable\mysong.ogg"

 

As far as being variable?
You can not directly
What you can do is put a user option in the script NumOfSongs
User must declare the value for NumOfSongs 2 songs 10 songs etc

 

use the NumOfSongs value as your limiter

so like you did a rand 0 to NumOfSongs 
and user had song0.ogg song1.ogg and song2.ogg
 

then they would set NumOfSongs to 3
Youd get a random number from 0 to 2
just call that value TRAK for sake of arguement

 

Playsound "Wondertable\song"&(TRAK)&".ogg"

 

Or something similar to that, i may have the syntax a little off, but i cant bring up a table here to grab an example from

 

 


If you feel the need to empty your wallet in my direction, i don't have any way to receive it anyways

Spend it on Hookers and Blow


#31 eiserne_maske

eiserne_maske

    Hobbyist

  • Validating
  • PipPip
  • 37 posts
  • Location:Germany

  • Flag: Germany

  • Favorite Pinball: Most of them

Posted 13 December 2023 - 10:23 AM

Its all about getting music right from the start of a table.  The music path is correct, which is Visual Pinball\Music. Folder name is "Captain Future" (for this table). I use Windows 11 with VPX 10.72. All is running properly. The mp3 files are ok, as i tagged them also correctly, like i did in JPs ACDC for example. So it shouldnt be a song issue.
 
The script below is taken from here on vpforums.org to setup music for several tables. however it gives me a compiling error in line 110, no matter what i tried. Please advice.
Line 110 in this case is the Dim-command...
 
 
Sub MusicOn  
  Dim FileSystemObject, folder, r, ct, file, musicPath, myMusicFolder 'this is line 110 which gives me an error
    myMusicFolder = "Captain Future"
 
    Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
    musicPath = FileSystemObject.GetAbsolutePathName(".")
 
    musicPath = Left(musicPath, Len(musicPath) - 6) + "Music\"
    Set folder = FileSystemObject.GetFolder(musicPath + myMusicFolder)
    Randomize
    r = INT(folder.Files.Count * Rnd + 1)
    ct=1
    For Each file in folder.Files
 
 'get every file in myMusicFolder, for each one count it and see if the count matches the random number
        if ct = r Then  ' random file found
            if (LCase(Right(file,4))) = ".mp3" Then ' can only play mp3 files
               PlayMusic Mid(file, Len(musicPath) + 1, 1000) ' PlayMusic defaults to Visual Pinball\music\, need to get myMusicFolder\song name
            End If 
       End If
   ct = ct + 1
   Next
End Sub
 
Sub Table1_MusicDone()
MusicOn
End Sub


#32 Sir Random

Sir Random

    Enthusiast

  • Members
  • PipPipPip
  • 133 posts
  • Location:Ireland

  • Flag: Ireland

  • Favorite Pinball: Jubilee, Eight Ball, Super Mario Bros

Posted 13 December 2023 - 03:44 PM

 

Its all about getting music right from the start of a table.  The music path is correct, which is Visual Pinball\Music. Folder name is "Captain Future" (for this table). I use Windows 11 with VPX 10.72. All is running properly. The mp3 files are ok, as i tagged them also correctly, like i did in JPs ACDC for example. So it shouldnt be a song issue.
 
The script below is taken from here on vpforums.org to setup music for several tables. however it gives me a compiling error in line 110, no matter what i tried. Please advice.
Line 110 in this case is the Dim-command...
 
 
 
  Dim FileSystemObject, folder, r, ct, file, musicPath, myMusicFolder 'this is line 110 which gives me an error
 

 

I don't see any problem with that line, I don't get any error when compiling with 10.73

The problem may be elsewhere, what is the error message you're getting?



#33 eiserne_maske

eiserne_maske

    Hobbyist

  • Validating
  • PipPip
  • 37 posts
  • Location:Germany

  • Flag: Germany

  • Favorite Pinball: Most of them

Posted 14 December 2023 - 07:39 AM

the error is actually an "invalid character" - if i did the translation correctly. (i have a german language VP setup )

 

is anything else needed to get this "stand alone" script started within the whole table script, i.e. a certain command at the table_init?