Jump to content



Photo
* * * * * 4 votes

Add Music / Audio to older tables : Mini-Script Tutorial

Add Music to tables script mp3 VPX HiRez00

  • Please log in to reply
32 replies to this topic

#1 HiRez00

HiRez00

    VPX / Pinball Contributor

  • Silver Supporter
  • 378 posts
  • Location:Los Angeles, CA

  • Flag: United States of America

  • Favorite Pinball: Too many to list here ...

Posted 16 January 2020 - 02:40 PM

Greetings all,

Let me start off by saying 'thank you' to all the VPX tables makers and scripting gurus here.

This is probably very basic scripting to most seasoned builders, but for me, it was a huge step because I am a basic 'noob' when it comes to table creation and scripting. Other than changing options provided by some table makers at the top of some table scripts, I know nothing about scripting at all, which is why I was really pleased when I got the following to work.

- - - - - - - - - - - - - - - - - - - - - - - - -

On some older tables, especially music themed ones, I wanted to add background mp3 music playing while pinballing. Now some table makers add music options to tables and sometimes add the music option to newer releases, but many times the mp3 music track would start playing when the ball was pushed into the plunger lane, or when the ball was fired from the plunger. Usually the mp3 audio track would abruptly END when the ball drained (lost ball) and then the next music track would start when the next ball is played.

This is all good and one some tables this is fine, but if you are having a sucky day and not playing pinball well that day, you only hear the first 15-20 seconds of a song and then it ends because you have lost the ball (drained) and you don't get into a 'rhythm' of playing out the song in its entirety ... which can be very frustrating.

Some newer Stern tables like Metallica or AC/DC give you the option of selecting a single song when gameplay is started and then has loop portions of the song and the song progresses as you play, which is a nice feature. Those particular tables, and others, allow you to change the music track mid-play, which is also nice.

But for older 70s and 80s tables, the ROM sounds are pretty basic.

So, I was on a mission ...

I wanted to share a script I managed to cobble together / write / get to work for use in some of my older style "music themed" tables like Kiss (Bally), Rolling Stones (Bally) and even Playboy (Bally) - 70s disco theme, using the 'built in mp3 player in VPX.

I wanted the music / audio to 'enhance' the gameplay, and not overpower it or completely replace the ROM sound and never go back. I wanted something I could turn on and off at my leisure and also keep the original game intact.

Here's what I did.

- - - - - - - - - - - - - - - - - - - - - - - - -

Open the script window for the table you want to add music / audio to and do a script search for: "Sub Table1_KeyDown"

Search show returns a line somewhere near the top of the script code that read:
 

Sub Table1_KeyDown(ByVal keycode)

Insert these (2) lines immediately after the Sub Table1_KeyDown(ByVal keycode) line

    If KeyCode = RightMagnaSave Then NextTrack
    If KeyCode = LeftMagnaSave Then EndMusic

So your addition should look like this:
 

Sub Table1_KeyDown(ByVal keycode)
    If KeyCode = RightMagnaSave Then NextTrack
    If KeyCode = LeftMagnaSave Then EndMusic

Now, a little further down, somewhere in-between some of the other subroutines in the script, cut and paste / add the following lines:
 

'******************************
'*     HiRez00: Music Mod     *
'******************************

Dim musicNum
Sub NextTrack

If musicNum = 0 Then PlayMusic "YourMusicTrack.mp3" End If
If musicNum = 1 Then PlayMusic "YourMusicTrack.mp3" End If
If musicNum = 2 Then PlayMusic "YourMusicTrack.mp3" End If
If musicNum = 3 Then PlayMusic "YourMusicTrack.mp3" End If
If musicNum = 4 Then PlayMusic "YourMusicTrack.mp3" End If
If musicNum = 5 Then PlayMusic "YourMusicTrack.mp3" End If
If musicNum = 6 Then PlayMusic "YourMusicTrack.mp3" End If
If musicNum = 7 Then PlayMusic "YourMusicTrack.mp3" End If
If musicNum = 8 Then PlayMusic "YourMusicTrack.mp3" End If
If musicNum = 9 Then PlayMusic "YourMusicTrack.mp3" End If

musicNum = (musicNum + 1) mod 10

End Sub

Sub Table1_MusicDone
        NextTrack

End Sub

'*****************************
'*       End Music Mod       *
'*****************************

Keep all the 'apostrophes" and other lines intact. Simply change the YourMusicTrack.mp3 in each line to the song / music file name you are using. i.e.: My Cool Music.mp3 or Lick it Up.mp3 - etc.

You can add as many audio tracks and 'If musicNum = x Then PlayMusic ..." lines as you like, just make sure to change the musicNum number as you go.

Then in the "musicNum = (musicNum + 1) mod 10" line, change the 10 number to 1 number higher than the 'If musicNum; lines or the total number of tracks you are adding. Remember you start a 0 at the top of the script, so the number is 1 higher than the 'If musicNum' line. Hope this makes sense.

Add all your mp3 music files to the "Music" folder in Visual Pinball - then - and this is important ... go to the "Music" folder. Select all your mp3 music files and RIGHT CLICK on them go to properties, then select details. You want to 'Remove all Additional Data' from the music files i.e.: artists, album, track number etc because this is the additional data that is stored in the 'IDE' of the mp3 files that sometimes messes with the mp3 playback engine in VPX. When you remove all this additional data, the files will play in VPX with no problem.

Save your table and script changes, then start up the table.

Remember, the music will not automatically start, you need to press the RIGHT MagnaSave button for the music to start. I did it this way so I can still play the table with all the original chimes and sounds without any music if I wanted to ... call me nostalgic.

If you press the RIGHT MagnaSave button again, the player will automatically jump to the next music track.

You can let the music play and NOT press the Right MagnaSave and when the audio track ends, it will automatically jump to the next one. When it gets to the end of all your music tracks, it will automatically start track 1 again, etc.

If you press the LEFT MagnaSave button, the player will STOP all music. You can press the RIGHT MagnaSave button to resume playing your music tracks.

If the sounds and chimes from the original table ROMS are overpowering your music, press the F12 button to adjust the ROM volumes so you have a nice balance of ROM sound and your music. These changes are automatically saved in the registry file so you will have the same settings for this particular ROM the next time you play a table that uses it.

- - - - - - - - - - - - - - - - - -

Like I said, this is really basic scripting. But I think other 'inexperienced' VPX users would learn something from my efforts.

Hope you find this script and tutorial interesting, helpful and useful.

 


Edited by HiRez00, 12 April 2020 - 04:13 PM.

-HiRez00


#2 mr359

mr359

    Neophyte

  • Members
  • Pip
  • 4 posts

  • Flag: Canada

  • Favorite Pinball: currently re discovering Future Pins

Posted 17 January 2020 - 07:21 PM

i read the first part of this - got lost in the scripting jargon, lol.  But I like this idea! cant wait to give it a try when I get to do my own cab !

 

- and the original; Jonny Quest  - hows that coming along?  awesome potential  - one of my favorites



#3 HiRez00

HiRez00

    VPX / Pinball Contributor

  • Silver Supporter
  • 378 posts
  • Location:Los Angeles, CA

  • Flag: United States of America

  • Favorite Pinball: Too many to list here ...

Posted 18 January 2020 - 02:30 PM

i read the first part of this - got lost in the scripting jargon, lol.  But I like this idea! cant wait to give it a try when I get to do my own cab !

 

- and the original; Jonny Quest  - hows that coming along?  awesome potential  - one of my favorites

I hear ya. I was the same way originally and couldn't make heads or tails of script notes. I tried my best to make it as easy as possible.

 

Make a backup original copy of any table you make changes to, so worst come to worst, you always have a backup ...

 

Still working on the 3 tables listed in my signature. My buddy, Xenonph, who does all the scripting work with lights and sound if offline for a little while. When he returns, we will resume work on those tables.


-HiRez00


#4 dkane626

dkane626

    Neophyte

  • Members
  • Pip
  • 4 posts

  • Flag: United States of America

  • Favorite Pinball: Monster Bash, CFTBL

Posted 17 March 2020 - 06:27 AM

This is awesome! I got it up and running very easily. Just curious if it would be easy to adjust the code if we DID want a song to start when the table first loads? Thanks so much for your code and help.



#5 HiRez00

HiRez00

    VPX / Pinball Contributor

  • Silver Supporter
  • 378 posts
  • Location:Los Angeles, CA

  • Flag: United States of America

  • Favorite Pinball: Too many to list here ...

Posted 17 March 2020 - 10:56 PM

This is awesome! I got it up and running very easily. Just curious if it would be easy to adjust the code if we DID want a song to start when the table first loads? Thanks so much for your code and help.

 

I don't know off hand ... let me do some experimenting and will get back to you in a day or so on this ...


-HiRez00


#6 Moxxidude

Moxxidude

    Hobbyist

  • Members
  • PipPip
  • 17 posts

  • Flag: Canada

  • Favorite Pinball: Comet

Posted 11 April 2020 - 09:56 PM

Wow! Thank you for the detailed hand-holding script information Hi-Rez00!! I was able to add hits from 1978 directly into the Playboy Bally Table. Worked like a charm first time and that NEVER happens!! I'd love to be able to do this on EM tables that don't have that particular line of coding to insert...guess I'll hunt around and see. Once again, thank you very much! Now I'm off to screw around with Rolling Stones and Kiss...



#7 Moxxidude

Moxxidude

    Hobbyist

  • Members
  • PipPip
  • 17 posts

  • Flag: Canada

  • Favorite Pinball: Comet

Posted 13 April 2020 - 02:03 PM

I found this easy code if you want music to play when a Table starts.

 

PlayMusic "insert_song_title.mp3"

 

I put the code near the top of the script and it works. Make sure of course, to put your mp3 in the VisualPinball/Music folder as usual. I'm not sure how to get other songs to play (or even how to loop the one song) but this definitely works and starts as soon as the table loads. But please note that the song starts and plays and ends. It doesn't restart when you start another game; you have to reload the table to start the song again - so it's not ideal. 

 

I'd love it if it could be like the coding above where we start and stop music with the MagnaSaves and have multiple songs - but the code/scripting above by HiRez00 only works if your table has: Sub Table1_KeyDown

 

I used HiRez00 script in Playboy (Bally), Rolling Stones (Bally), Captain Fantastic and Dolly Parton. Thanks again HiRez00!



#8 fireslayer26

fireslayer26

    Hobbyist

  • Members
  • PipPip
  • 28 posts

  • Flag: United States of America

  • Favorite Pinball: The Last Dragon

Posted 14 April 2020 - 02:45 AM

I just used this on my "The Last Dragon" table. I'm using the "Back to the Future" table by cyperpez as the base. Works great! Thanks!



#9 fireslayer26

fireslayer26

    Hobbyist

  • Members
  • PipPip
  • 28 posts

  • Flag: United States of America

  • Favorite Pinball: The Last Dragon

Posted 14 April 2020 - 02:11 PM

One thing I've noticed though. When one song ends, the next song is not starting unless I hit the Right Magnasave again. What do I need to add to the script to have the next song automatically start?

 

Thanks

 

**UPDATE**

 

Got it working.

 

I had to change "Sub Table1_MusicDone" to Sub bttf_MusicDone"  since that is the name used elsewhere in the script.


Edited by fireslayer26, 14 April 2020 - 02:41 PM.


#10 mitshiba

mitshiba

    Neophyte

  • Members
  • Pip
  • 2 posts

  • Flag: United States of America

  • Favorite Pinball: Addams Family

Posted 18 June 2020 - 02:54 AM

Out of curiosity, is there a way to set the volume of the music in the script instead of it playing at 100%?



#11 HiRez00

HiRez00

    VPX / Pinball Contributor

  • Silver Supporter
  • 378 posts
  • Location:Los Angeles, CA

  • Flag: United States of America

  • Favorite Pinball: Too many to list here ...

Posted 18 June 2020 - 04:31 AM

Out of curiosity, is there a way to set the volume of the music in the script instead of it playing at 100%?


As of now with vp 10.6, no. But you can adjust the volumes of the mp3s with a free program like “Audacity” so they all play at the same volume.

Supposedly, and I am not 100% sure about this, that VPX 10.7 WILL have the ability to set volumes per mp3 audio track.

But, to be safe, I would suggest setting the volumes manually per track with audacity or similar audio program.

-HiRez00


#12 MonkeyKing

MonkeyKing

    Neophyte

  • Members
  • Pip
  • 5 posts

  • Flag: Costa Rica

  • Favorite Pinball: Indiana Jones

Posted 18 June 2020 - 03:09 PM

This is great, I was using a autohotkey script and a command line mp3 player to add music to some tables but it would be nicer to build it in.

 

I'd prefer it if it selected a random track to play, but I can't figure out how to generate a random number in VPX. Do you know the command? It should then be pretty easy to modify the script.



#13 Greynurse

Greynurse

    Enthusiast

  • Members
  • PipPipPip
  • 321 posts
  • Location:Australia

  • Flag: Australia

  • Favorite Pinball: DOOM by Bigus1

Posted 19 June 2020 - 12:08 PM

For some of us, it's the perfect storm of pinball and jukebox combined. Thanks HiRez for this lovely little script.

A word on using Audacity to adjust volumes. Normalising a track means that it will set the volume of the largest peak on the wave pattern to the maximum db. This is OK for most music, but if you have a track with a large dynamic range (very quiet segments set against very loud segments) or just a large "spike" in the wave pattern, the some or most of the music may be hard to hear. I use the Amplify effect. It seems to work better at seting a constant volume. If you come across a track with just one large spike, you can always either cut it out, or zoom in on it, select it, and reduce it's volume to match the rest of the track.

 

Cheers,

Nursie



#14 HiRez00

HiRez00

    VPX / Pinball Contributor

  • Silver Supporter
  • 378 posts
  • Location:Los Angeles, CA

  • Flag: United States of America

  • Favorite Pinball: Too many to list here ...

Posted 19 June 2020 - 02:35 PM

For some of us, it's the perfect storm of pinball and jukebox combined. Thanks HiRez for this lovely little script.

A word on using Audacity to adjust volumes. Normalising a track means that it will set the volume of the largest peak on the wave pattern to the maximum db. This is OK for most music, but if you have a track with a large dynamic range (very quiet segments set against very loud segments) or just a large "spike" in the wave pattern, the some or most of the music may be hard to hear. I use the Amplify effect. It seems to work better at seting a constant volume. If you come across a track with just one large spike, you can always either cut it out, or zoom in on it, select it, and reduce it's volume to match the rest of the track.

 

Cheers,

Nursie

You are correct. And like you say - for most cases this is ok with music.

 

Personally I use the mp3gain program for all music in my touch screen jukebox system. https://sourceforge....ojects/mp3gain/


-HiRez00


#15 mitshiba

mitshiba

    Neophyte

  • Members
  • Pip
  • 2 posts

  • Flag: United States of America

  • Favorite Pinball: Addams Family

Posted 22 June 2020 - 05:27 PM

Awesome sauce, Thanks again @HiRez00 

 

I've been checking the progress of 10.7 every so often and testing it on my cab, it works beautifully (well almost beautifully, soon as most of the bugs are worked around). Love the physics and looking forward to able to use individual mp3 volume functions :)



#16 RYAND1

RYAND1

    Neophyte

  • Members
  • Pip
  • 1 posts

  • Flag: United States of America

  • Favorite Pinball: Gorgar

Posted 11 July 2020 - 12:18 PM

Hello, Is there a way to have a song start with the table and then make it end with the start key only to play a different song when the

start key is pressed?



#17 rockclimber

rockclimber

    Enthusiast

  • Members
  • PipPipPip
  • 61 posts

  • Flag: United Kingdom

  • Favorite Pinball: haunted house

Posted 12 July 2020 - 06:10 PM

Thanks HiRez00, Ive just book marked this page so that when I do build my cab I'm going to give it a go. Just collecting all the bits together at the moment and i'm going to build it with SSF. Ive got the amps and exciter speakers and am looking to use pinvol to set all the table volumes to the same levels. Will be interesting to see if it adjusts the mp3 volume as well. Thanks again.



#18 mrjcrane

mrjcrane

    Pinball Fan

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

  • Flag: United States of America

  • Favorite Pinball: Monster Bash

Posted 02 February 2021 - 04:19 PM

This is great, I was using a autohotkey script and a command line mp3 player to add music to some tables but it would be nicer to build it in.
 
I'd prefer it if it selected a random track to play, but I can't figure out how to generate a random number in VPX. Do you know the command? It should then be pretty easy to modify the script.

So I saw in the recent Pabst Can Crusher table, code in the table script to play 1 of 15 random music track mp3 files in a continuous play mode, plays each entire song, then selects next track at random. When I figure out how to add script code for random tracks instead of sequential tracks using HiRez's magnasave advancing method, I'll post the solution. Thanks HiRez for this tutorial.

Edited by mrjcrane, 02 February 2021 - 04:23 PM.


#19 HiRez00

HiRez00

    VPX / Pinball Contributor

  • Silver Supporter
  • 378 posts
  • Location:Los Angeles, CA

  • Flag: United States of America

  • Favorite Pinball: Too many to list here ...

Posted 02 February 2021 - 04:55 PM

 

This is great, I was using a autohotkey script and a command line mp3 player to add music to some tables but it would be nicer to build it in.
 
I'd prefer it if it selected a random track to play, but I can't figure out how to generate a random number in VPX. Do you know the command? It should then be pretty easy to modify the script.

So I saw in the recent Pabst Can Crusher table, code in the table script to play 1 of 15 random music track mp3 files in a continuous play mode, plays each entire song, then selects next track at random. When I figure out how to add script code for random tracks instead of sequential tracks using HiRez's magnasave advancing method, I'll post the solution. Thanks HiRez for this tutorial.

 

 

@mrjcrane

I actually already have the code to do that. If you take a look at my Rolling Stones or newer Playboy 1978 (I don't have access to those scripts at the moment) - you can see how I did it using a random number generator to pick the track.


-HiRez00


#20 mrjcrane

mrjcrane

    Pinball Fan

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

  • Flag: United States of America

  • Favorite Pinball: Monster Bash

Posted 03 February 2021 - 03:14 AM

Hi Rez thanks i learned a lot from your script. I added some script mods over in the new PBR Can Crusher table. I ended up going with the manual track advancement as you originally suggested. The script mod is simple enough, it is a good learning exercise for someone new to scripting mods for tables, myself included, Thanks again. 

 

https://www.vpforums...=46019&p=468312


Edited by mrjcrane, 03 February 2021 - 03:15 AM.






Also tagged with one or more of these keywords: Add, Music, to tables, script, mp3, VPX, HiRez00