Wait, when I added pyglet.media.dispatch_events() to my running loop,
it worked. Thanks!
On Nov 8, 10:30 am, Noyan Tokgozoglu <[EMAIL PROTECTED]> wrote:
> The OS is Windows XP. THe problem with the event loop is in the code I
> posted previously. The sound looping problem was in the following
> code, which I changed into the previous code. I'd rather if I could
> keep the code in the original way and still have sounds not loop.
> The code:
>
> import psyco
> psyco.full()
> import pyglet
> from pyglet import window
> from pyglet.gl import *
> from pyglet.window import mouse
> from pyglet.window import key
> import math
> import pyglet.clock
>
> WIDTH = 1024
> HEIGHT = 768
> VERSION = 'alpha 0.1'
> win = window.Window(width=WIDTH,height=HEIGHT,visible=False)
> win.set_caption('concert drummer '+VERSION)
> dt = 0
> kick = [key.Z,key.X]
> snare = [key.S,key.D]
> hihat = [key.E,key.R]
> ride = [key._3,key._4]
> crash = [key.T,key.Y]
> keys =
> {'kick':kick,'snare':snare,'hihat':hihat,'ride':ride,'crash':crash}
> kicks = pyglet.media.load('kick.ogg', streaming=False)
> snares = pyglet.media.load('snare.ogg', streaming=False)
> sounds = {'kick':kicks,'snare':snares}
>
> time = 0
> track = []
> bpm = 0
>
> quadratic=0
>
> @win.event
> def on_key_press(symbol, modifiers):
> global clock, keys,sounds
> if symbol in keys['kick']:
> sounds['kick'].play()
> if symbol in keys['snare']:
> sounds['snare'].play()
> def vec(*args):
> return (GLfloat * len(args))(*args)
> def resize(width, height):
> if height==0:
> height=1
> glViewport(0, 0, width, height)
> glMatrixMode(GL_PROJECTION)
> glLoadIdentity()
> gluPerspective(45, 1.0*width/height, 0.1, 2561.0)
> glMatrixMode(GL_MODELVIEW)
> glShadeModel(GL_SMOOTH)
> glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
>
> glClearColor(0.5,0.5,0.5,1.0)
> glLoadIdentity()
> """glEnable(GL_LIGHTING)
> #glEnable(GL_LIGHT0)
> glEnable(GL_LIGHT1)
> glLightfv(GL_LIGHT0, GL_POSITION, vec(1, 1, 1, 0))
> glLightfv(GL_LIGHT0, GL_SPECULAR, vec(1, 1, 1, 1))
> glLightfv(GL_LIGHT0, GL_DIFFUSE, vec(1, 1, 1, 1))
> glLightfv(GL_LIGHT1, GL_AMBIENT, vec(1, 1, 1, 1))
> glLightfv(GL_LIGHT1, GL_DIFFUSE, vec(1, 1, 1, 1))
> glLightfv(GL_LIGHT1, GL_POSITION, vec(0, 0, 0, 1))
> glEnable (GL_DEPTH_TEST)
> #glEnable(GL_COLOR_MATERIAL)
> glColorMaterial ( GL_FRONT_AND_BACK, GL_DIFFUSE ) """
> #glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT )
> #glMateriali(GL_FRONT_AND_BACK, GL_SHININESS,vec(1,1,1,1))
> #glMateriali(GL_FRONT_AND_BACK, GL_SHININESS,vec(0,0,0,1))
> """glEnable(GL_FOG)
> glFogi(GL_FOG_MODE, GL_LINEAR)
> glFogfv(GL_FOG_COLOR, vec(.5, .5, .5, 1.))
> glFogf(GL_FOG_DENSITY, 2)
> glHint(GL_FOG_HINT, GL_NICEST)
> glFogf(GL_FOG_START, 10.0)
> glFogf(GL_FOG_END, 40.0) """
>
> def init():
> global quadratic
> glShadeModel(GL_SMOOTH)
> glClearDepth(1.0)
> glEnable(GL_DEPTH_TEST)
> glDepthFunc(GL_LEQUAL)
> glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
> #glEnable(GL_LIGHTING)
> glEnable(GL_POLYGON_SMOOTH)
> quadratic = gluNewQuadric()
> gluQuadricNormals(quadratic, GLU_SMOOTH)
> gluQuadricTexture(quadratic, GL_TRUE)
>
> def draw():
> global win,quadratic,track,time,HEIGHT
> glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
> glLoadIdentity()
>
> glRotatef(30,1,0,0)
> glTranslatef(0,-10,-9)
> #glRotatef(120,1,0,0)
>
> step = time * bpm *16.0/ 60.0
> glTranslatef(-6,0,step)
> for i in range(len(track)):
> if i*4 >= step and i*4 <= 80 + step:
> glPushMatrix()
> glTranslatef(0,0,-i*4)
> for j in range(len(track[i])):
> glTranslatef(2,0,0)
> if track[i][j] == 1:
> glPushMatrix()
> glRotatef(90,1,0,0)
> glColor3f(1,1,1)
> gluDisk(quadratic,0,.6,32,32)
> if j == 0:
> glColor3f(1,0,0)
> elif j == 1:
> glColor3f(0,1,0)
> elif j == 2:
> glColor3f(0,0,1)
> gluCylinder(quadratic,.6,.8,.5,32,32)
> glPopMatrix()
> glPopMatrix()
>
> def main():
> global win,dt,bpm,track,time
> win.on_resize = resize
> init()
> clock=pyglet.clock.Clock()
> win.switch_to()
> win.set_visible()
>
> drumfile = open('test.ndm','r')
> drumfile = drumfile.readlines()
> bpm = int(drumfile[0])
> drumfile = drumfile[1:len(drumfile)]
> drumfile = drumfile[1:len(drumfile)]
> for item in drumfile:
> toadd = []
> for char in item[0:-1]:
> if char == '1':
> toadd.append(1)
> else:
> toadd.append(0)
> track.append(toadd)
>
> while not win.has_exit:
> win.dispatch_events()
> draw()
> win.flip()
> dt = clock.tick()
> time += dt
>
> if __name__ == '__main__': main()
>
> On Nov 8, 1:23 am, "Alex Holkner" <[EMAIL PROTECTED]> wrote:
>
>
>
> > On 11/8/08, Noyan Tokgozoglu <[EMAIL PROTECTED]> wrote:
>
> > > Hello all, I was writing code in a pyglet 1.0-1.1 mixed way, then when
> > > I tried to play sounds I discovered that they loop eternally unless I
> > > use the run() method.
>
> > Make sure you call each player's dispatch_events() method, as well as
> > pyglet.media.dispatch_events().
>
> > > However every update I need to assign a value to
> > > a variable I call time, and I can't do that with a standard app loop.
>
> > pyglet.clock.schedule(func) will do this (it will also prevent the
> > loop from sleeping; use schedule_interval for a regular timed update).
>
> > > So I customize my app, but now it doesn't even draw anything, and
> > > sounds still loop eternally! Help! What must I do?
>
> > I couldn't see the problem immediately; if you still need help I
> > suggest posting a complete working example, and which OS you are
> > targeting.
>
> > Alex.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---