Jump to content



Photo
* * * * * 1 votes

Adding music (mp3's) to a table?


  • Please log in to reply
32 replies to this topic

#1 jdsabin1

jdsabin1

    Enthusiast

  • Members
  • PipPipPip
  • 219 posts
  • Location:Central USA

  • Flag: United States of America

  • Favorite Pinball: A sucker for EM tables....

Posted 01 April 2011 - 02:27 PM

Everyone - JP added some very fun mp3's to a few older tables (fast draw and el dorado) and IMHO it makes the gameplay a real hoot to play. How hard is it to do this in other tables? I was thinking I'd love to do this to a table like KISS for example so along with the rudimentary midi sounds you could get some classic KISS songs playing as well.

Just curious as to how difficult this might be is all.

Thanks.
'The ball is wild!' - Harry Williams

#2 faralos

faralos

    VPF Veteran

  • Members
  • PipPipPipPipPipPip
  • 7,838 posts
  • Location:Eastern Pa,USA

  • Flag: United States of America

  • Favorite Pinball: Flash (Williams) 1979, Flash2 Updated




  • Trophies:

Posted 01 April 2011 - 02:53 PM

all yas' gotta' do is put the mp3's into a music folder labeled 'music; then when we get the pin we know to also look for the music folder for it. the vp engine will call out for the music in game with the proper coding. it is not hard just needs that extra folder which many of us find annoying but it makes for the pin size to be lessened tremendously if you keep the music out of it. I have this current wip that is over 80 megs all due to the songs in it, if the music were in a separate folder the pin size would be only around 12 megs! that is the difference in sheer size due to the music files (usally I record in mono but with this pin I needed them in stereo greatly expanding their file size from around 4 mgs mono to about 12 megs stereo!
but again I like the music in the pin as it's a simpler download and I have yet to code a mp3 file into one.
"Don’t let the noise of others’ opinions drown out your own inner voice.
And most important, have the courage to follow your heart and intuition.”
----Steve Jobs


#3 jdsabin1

jdsabin1

    Enthusiast

  • Members
  • PipPipPip
  • 219 posts
  • Location:Central USA

  • Flag: United States of America

  • Favorite Pinball: A sucker for EM tables....

Posted 01 April 2011 - 03:04 PM

So is there some standard code that gets put in the table script then or ... ?
'The ball is wild!' - Harry Williams

#4 clyde

clyde

    Pinball Fan

  • Gold Supporter
  • 613 posts
  • Location:Martinsville VA

  • Flag: United States of America

  • Favorite Pinball: Monster Bash

Posted 01 April 2011 - 04:41 PM

Here's how i have it in JP's KISS table,



'Start the music from Fast Draw table
MusicOn
End Sub

Sub table1_Paused:Controller.Pause = 1:End Sub
Sub table1_unPaused:Controller.Pause = 0:End Sub

Sub MusicOn
Dim x
x = INT(5 * RND(1) )
Select Case x
Case 0:PlayMusic "I Wanna Rock & Roll All Night.mp3"
Case 1:PlayMusic "I Was Made For Loving You.mp3"
Case 2:PlayMusic "Lick It Up.mp3"
Case 3:PlayMusic "Shout It Out Loud.mp3"
Case 4:PlayMusic "Russian Roulette.mp3"
Case 5:PlayMusic "Crazy Crazy Nights.mp3"
Case 6:PlayMusic "Psycho Circus.mp3"
Case 7:PlayMusic "Reason To Live.mp3"
End Select
End Sub

Sub Table1_MusicDone()
MusicOn
End Sub

#5 jdsabin1

jdsabin1

    Enthusiast

  • Members
  • PipPipPip
  • 219 posts
  • Location:Central USA

  • Flag: United States of America

  • Favorite Pinball: A sucker for EM tables....

Posted 01 April 2011 - 06:44 PM

Thanks so much! smile.gif
'The ball is wild!' - Harry Williams

#6 ebarlow99

ebarlow99

    Ass Kicker

  • Members
  • PipPipPip
  • 349 posts
  • Location:MI

  • Flag: United States of America

  • Favorite Pinball: ALL

Posted 11 June 2011 - 03:56 AM

QUOTE (clyde @ Apr 1 2011, 12:41 PM) <{POST_SNAPBACK}>
Here's how i have it in JP's KISS table,



'Start the music from Fast Draw table
MusicOn
End Sub

Sub table1_Paused:Controller.Pause = 1:End Sub
Sub table1_unPaused:Controller.Pause = 0:End Sub

Sub MusicOn
Dim x
x = INT(5 * RND(1) )
Select Case x
Case 0:PlayMusic "I Wanna Rock & Roll All Night.mp3"
Case 1:PlayMusic "I Was Made For Loving You.mp3"
Case 2:PlayMusic "Lick It Up.mp3"
Case 3:PlayMusic "Shout It Out Loud.mp3"
Case 4:PlayMusic "Russian Roulette.mp3"
Case 5:PlayMusic "Crazy Crazy Nights.mp3"
Case 6:PlayMusic "Psycho Circus.mp3"
Case 7:PlayMusic "Reason To Live.mp3"
End Select
End Sub

Sub Table1_MusicDone()
MusicOn
End Sub


is there a certain spot in the script? also where do the mp3's need to be stored table folder?


#7 faralos

faralos

    VPF Veteran

  • Members
  • PipPipPipPipPipPip
  • 7,838 posts
  • Location:Eastern Pa,USA

  • Flag: United States of America

  • Favorite Pinball: Flash (Williams) 1979, Flash2 Updated




  • Trophies:

Posted 11 June 2011 - 10:45 AM

um I think that code is for a song to play randomly: x = INT(5 * RND(1) ) I think this means it'll pick a song randomly out of the list hence the: select case x line where x is any one of them and it usually goes into where everything else gets 'dimmed' at the top of the script
again Do not quote me here as I have yet to put any mp3's into my wip's I stick with wav. files this way I know the person getting the table gets the music since wav.'s are written into the script and mp3's are in an external folder (the music folder in your vp folder)
this is not tech support just MY PERSONAL OPINION just making this clear

Edited by faralos, 11 June 2011 - 10:46 AM.

"Don’t let the noise of others’ opinions drown out your own inner voice.
And most important, have the courage to follow your heart and intuition.”
----Steve Jobs


#8 ebarlow99

ebarlow99

    Ass Kicker

  • Members
  • PipPipPip
  • 349 posts
  • Location:MI

  • Flag: United States of America

  • Favorite Pinball: ALL

Posted 11 June 2011 - 12:42 PM

ok...thought it would be cool to have some diff music playing while im playing tables.....

#9 sleepy

sleepy

    Pinball Fan

  • Members
  • PipPipPipPip
  • 705 posts

  • Flag: United States of America

  • Favorite Pinball: Tiny Tim and The Ghost of Christmas Present

Posted 11 June 2011 - 01:22 PM

Put the .mp3 files in the Visual Pinball\Music folder.

Then in the script add:

PlayMusic "NameOfFile.mp3"

You can put this in a Sub for a Bumper_Hit() or inside of an If/Then statement when the points reach a certain score, or Extra Ball, etc., just about anywhere, but best to put the line inside of a Sub on an event like Bumper_Hit, Kicker_Hit, etc.

Use EndMusic() to stop.

#10 Bob5453

Bob5453

    I'm taking a nap

  • VIP
  • 3,896 posts
  • Location:Near Dayton, Ohio USA

  • Flag: United States of America

  • Favorite Pinball: Any table I can play while sitting in a rocking chair




  • Trophies:

Posted 11 June 2011 - 03:07 PM

QUOTE (clyde @ Apr 1 2011, 12:41 PM) <{POST_SNAPBACK}>
Here's how i have it in JP's KISS table,



'Start the music from Fast Draw table
MusicOn
End Sub

Sub table1_Paused:Controller.Pause = 1:End Sub
Sub table1_unPaused:Controller.Pause = 0:End Sub

Sub MusicOn
Dim x
x = INT(5 * RND(1) )
Select Case x
Case 0:PlayMusic "I Wanna Rock & Roll All Night.mp3"
Case 1:PlayMusic "I Was Made For Loving You.mp3"
Case 2:PlayMusic "Lick It Up.mp3"
Case 3:PlayMusic "Shout It Out Loud.mp3"
Case 4:PlayMusic "Russian Roulette.mp3"
Case 5:PlayMusic "Crazy Crazy Nights.mp3"
Case 6:PlayMusic "Psycho Circus.mp3"
Case 7:PlayMusic "Reason To Live.mp3"
End Select
End Sub

Sub Table1_MusicDone()
MusicOn
End Sub


In this example the random number generated will only be 1 through 5, so it will never play Psycho Circus.mp3 or Reason To Live.mp3

Posted Image

You have discovered an Easter egg. Pat yourself on the back.


#11 ebarlow99

ebarlow99

    Ass Kicker

  • Members
  • PipPipPip
  • 349 posts
  • Location:MI

  • Flag: United States of America

  • Favorite Pinball: ALL

Posted 11 June 2011 - 03:54 PM

QUOTE (sleepy @ Jun 11 2011, 09:22 AM) <{POST_SNAPBACK}>
Put the .mp3 files in the Visual Pinball\Music folder.

Then in the script add:

PlayMusic "NameOfFile.mp3"

You can put this in a Sub for a Bumper_Hit() or inside of an If/Then statement when the points reach a certain score, or Extra Ball, etc., just about anywhere, but best to put the line inside of a Sub on an event like Bumper_Hit, Kicker_Hit, etc.

Use EndMusic() to stop.



sweet...thanks will try later today!!

#12 vothar

vothar

    Enthusiast

  • Members
  • PipPipPip
  • 55 posts

  • Flag: Canada

  • Favorite Pinball: medieval madness

Posted 04 January 2020 - 03:39 PM

ok sorry, i dig this thread to add a question : how (can we ? ) to change the volume of a mp3 that you play with PlayMusic ?



#13 jlatko

jlatko

    Hobbyist

  • Members
  • PipPip
  • 10 posts

  • Flag: United States of America

  • Favorite Pinball: Wonka

Posted 09 June 2020 - 02:24 AM

I was wondering the same thing. Does PlayMusic accept any parameters like PlaySound does? No way to control volume with PlayMusic?

#14 Greynurse

Greynurse

    Enthusiast

  • Members
  • PipPipPip
  • 321 posts
  • Location:Australia

  • Flag: Australia

  • Favorite Pinball: DOOM by Bigus1

Posted 09 June 2020 - 02:31 AM

A non-script way is to use Audacity to normalise the sound. I've found that quiet tracks have a low amplitude. Normalising fixes that. Audacity is free and quite easy to use.

 

Cheers,

 

Nursie



#15 jpsalas

jpsalas

    Grand Schtroumpf

  • VIP
  • 6,393 posts
  • Location:I'm Spanish, but I live in Oslo (Norway)

  • Flag: Norway

  • Favorite Pinball: I like both new and old, but I guess I prefer modern tables with some rules and goals to achieve.



Posted 09 June 2020 - 03:52 AM

The playmusic command has no volume parameters. So for now you'll need to change the volume as Greynurse said, using an audio editor.

 

But in VPX 10.7 you'll be able to add the mp3 songs directly in the editor and play them with the PlaySound command :) It is working now in the beta, but the volume is way too high, toxie is working with it (this is why it is "beta")


These are my tables, sorted by date, all them playable with VPX 7 or newer:

vp.jpg

After 18 years making tables, it is time to take a rest and let new authors do their thing.

I guess at last I'll play some more pinball :). But I'm sure I'll make some table updates from time to time :)


#16 jogrady7

jogrady7

    Enthusiast

  • Platinum Supporter
  • 62 posts

  • Flag: United States of America

  • Favorite Pinball: Medieval Madness

Posted 07 November 2020 - 04:59 PM

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)
 
 
 

Edited by jogrady7, 01 February 2021 - 06:00 PM.


#17 Stavros75

Stavros75

    Neophyte

  • Members
  • Pip
  • 8 posts

  • Flag: Greece

  • Favorite Pinball: AC/DC

Posted 30 April 2022 - 08:44 PM

cannot figure this out, is this correct?

 

End Sub
 
Sub MusicOn
    Dim FileSystemObject, folder, r, ct, file, musicPath, myMusicFolder
    myMusicFolder = "ownmusic" ' 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


#18 FlatStick

FlatStick

    Neophyte

  • Members
  • Pip
  • 2 posts

  • Flag: Australia

  • Favorite Pinball: Seawitch

Posted 29 June 2022 - 07:27 AM

 

cannot figure this out, is this correct?

 

...

 

That is correct (from what I can see), but you need to make sure you add the commands in for the magna save buttons. The way I did it was to go into the script, then CTRL+F and do a search for "Keydown", and that takes me to the correct spot (as Jogrady7 shows).

 

Then, as long as the table is called table1, add in the two red lines from Jogrady7's post.

 

For example, this is what mine for my Iron Maiden 1981 table looks like:

 

Sub table1_KeyDown(ByVal Keycode)
    If keycode = LeftTiltKey Then Nudge 90, 5:PlaySound SoundFX("fx_nudge", 0), 0, 1, -0.1, 0.25
    If keycode = RightTiltKey Then Nudge 270, 5:PlaySound SoundFX("fx_nudge", 0), 0, 1, 0.1, 0.25
    If keycode = CenterTiltKey Then Nudge 0, 6:PlaySound SoundFX("fx_nudge", 0), 0, 1, 0, 0.25
    If vpmKeyDown(keycode)Then Exit Sub
    If keycode = PlungerKey Then PlaySoundat "fx_PlungerPull",Plunger:Plunger.Pullback
    If keycode = RightMagnaSave Then MusicOn
    If keycode = LeftMagnaSave Then EndMusic

    'If keycode = KeyRules Then Rules
End Sub

If you didn't do that bit then you can't get the music to start using the magna save buttons.
 


Jogrady7's script works great for me; but I notice it doesn't automatically run the random select process at the end of a song (at least not for me); is it supposed to?

 

Or, anyone know the script to add to to what jogrady7 posted that would make it choose another track at the end of each track? A bit annoying that I have to hit the magnasave button each time a song finishes.

 

Or have I done something wrong?



#19 Roadblock

Roadblock

    Enthusiast

  • Members
  • PipPipPip
  • 127 posts
  • Location:Moncton, NB

  • Flag: Canada

  • Favorite Pinball: Attack from Mars

Posted 29 June 2022 - 01:12 PM

https://www.vpforums...sic#entry453276



#20 FlatStick

FlatStick

    Neophyte

  • Members
  • Pip
  • 2 posts

  • Flag: Australia

  • Favorite Pinball: Seawitch

Posted 30 June 2022 - 10:49 AM

Legend, thanks Roadblock!

 

To anyone playing at home, the thread Roadblock pointed me to talks about the script for Playboy 1978 which I have, and it didn't click that that table was going to next track ok (d'oh); anyhoo, long story short, I ;poked around and worked out that if you add the following sub right after Jogrady7's script above, you'll get it to run the random routine again after each track.... it does mean though that sometimes you'll get the same song playing again, but this depends on how much music you jam into the folder you point it to.

 

---------

Sub Table1_MusicDone
        MusicOn

End Sub
-----------

 

Enjoy (and I'm new so I'm sorry if this is breaking any forum rules).