Can you please fix this code for me? The music is loaded and played but the timer doesnt run and the total duration isnt calculated 
the ‘length’ value doesnt exist…
I try to check it, when I have time, Just thinking things with doesn’t see, Are you sure thist script is execute once, not ‘pulse mode’
It is very interesting project by the way.
Thanks pohjan,
the script is connected to an always and no pulse mode. I did it because of the (own[‘timer’] = 0). currently i am still using the normal wave files, there should just be a small change for reading length of the ogg, everything else is okay.
I think the last line [‘reallenght’]=… newer executed due to errors
I thinking, what you are get with contextlib? and what is wave…open(…)
My quess? thast not work with mp3
Keep allways Blender console open when writing scripts.
What you see here?
Just ripe it, and set [‘lenght’] by manually to test.
Then we can thinking how to get real lenghts…
Try to learn drive scripts in Blender module mode.
#Musicplayer.py
#somekind pseudocode
import whatever
load sounds
reset counters
#This area executed just once, even pulse mode
def musicplayer():
#Calculate song advance etc..
#this are execute everey frame
#Now we prevent countinuosly bge importing too (complicated large library, import take time)
Now execution blocks is.
[allways, pulsemode on] --------[Python, module mode “Mypython.musicplayer” ]
edit: little more thoughts…
How you store beatmaps for song?
Just write lengts, artist info etc… to same textfile
this style: (Songname.txt)
duration=3:20
artist=???
#then it comes beats itself
time, controller, whatever
120, left arm
160, right arm
188, jump
210, jump
…
thanks pohjan.
the reallength value is the string value that shows the duration of the song like a clock ( 00:00 )
Uff, i have really few knowledge with programming ,including python . I think i get your explaination but i cannot turn it into a code ![]()
This is the way i make the beat map
…
Intro1
if own[‘offsetint’] == 691: #692
GameLogic.sendMessage(“k”)elif own[‘offsetint’] == 731: #732
GameLogic.sendMessage(“o”)
elif own[‘offsetint’] == 771: #772
GameLogic.sendMessage(“l”)
elif own[‘offsetint’] == 791: #792
GameLogic.sendMessage(“u”)
elif own[‘offsetint’] == 811: #812
GameLogic.sendMessage(“i”)
6 objects that creat the arrows are U I O J K L
offsetint value is the the value that runs 3/4 beat earlier than the current time, but converted into integer value
I wanted to record a part of a screen so i used hypercam, sry for bad quaity. There i let the console print the offsetint values. I was playing the game while recording too. If you hit the key it will be scaled and fade out. If you miss, it will turn to a black arrow and fly outside
Here is allmost ready solution, it stores beat times to global dictionary
logicbricks:
[allways, pulse on]------[Python module mode beat.beatshow]
beat.py
#Textloader
import bge
import time
import aud
beatfile="test.txt"
musicfile="Digitalbokea.ogg"
beattimes=[]
beatkeys=[]
with open(bge.logic.expandPath("//"+beatfile), 'r') as f:
for lines in f:
line=lines.strip()
doit=True
if 'artist' in line:
null,bge.logic.globalDict['artist']=line.split('=')
doit=False
if 'duration' in line:
null,bge.logic.globalDict['duration']=line.split('=')
doit=False
if doit:
beattime,key=line.split(",")
beattimes.append(int(beattime))
beatkeys.append(key)
print (beattimes,beatkeys)
#Store beatlists to globalDict
bge.logic.globalDict['times']=beattimes
bge.logic.globalDict['keys']=beatkeys
device = aud.device()
factory = aud.Factory(bge.logic.expandPath("//"+musicfile))
factory_buffered = aud.Factory.buffer(factory)
#We get audio buffered to memory, it eats memory, but timing is so important
_starttime=time.time()
bge.logic.globalDict['start']=_starttime # Store starting time to globaldict
bge.logic.globalDict['listcount']=0
handle = device.play(factory_buffered)
def beatshow():
dtime=int((time.time()-bge.logic.globalDict['start'])*60)
bcount=bge.logic.globalDict['listcount']
btime=bge.logic.globalDict['times'][bcount]
bkeys=bge.logic.globalDict['keys'][bcount]
if dtime>btime:
print ("Beat at:")
bge.logic.globalDict['listcount']+=1
bge.logic.sendMessage(bkeys)
print (dtime)
and test.txt (make sure you have not! empty lines, parser is very limited)
duration=2:30
artist=Nomebody
691,k
731,o
771,l
791,u
811,i
999999999,this line with never reached
Here is blends too
musicshow.zip (2.1 MB)
thank you very much pohjan! i learn alot from you
Thank you so much! I’ve been looking for a replacement to PyGame for ages and this does the job perfectly. I changed to AUD a long time ago for playing sound, but I couldn’t find a better way to get the sound length.
dtime=int((time.time()-vm['start'])*60) #secs*60=fps 4 deltime=dtime+180/vm['bpm'] min = ? sec=int(dtime/60) mili=int(dtime%60) vm['elapsed']=str(sec)+":"+str(mili) deltimeint = int(str(sec)+""+str(mili)) bcount=vm['listcount'] btime=vm['times'][bcount] bkeys=vm['keys'][bcount] if deltimeint>btime: print ("Beat at:") vm['listcount']+=1 bge.logic.sendMessage(bkeys)
print (dtime)
hello everyone, i need some help to receive the minute value from the ‘dtime’, what should i input there?