Explicitly finishing a SoundInterval within a Sequence

Hi,

I would like to explicitly finish a SoundInterval which is part of a Sequence. But the result is not as expected.
The audio file encapsulated by the SoundInterval is stopped properly but not the SoundInterval itself.

This is the (test) code:

import os
resourceDir = os.path.dirname(os.path.abspath(__file__)) + <INSERT RES DIR HERE>

from pandac.PandaModules import loadPrcFileData
loadPrcFileData('', 'audio-library-name p3openal_audio')
loadPrcFileData('', 'model-path ' + resourceDir)

import direct.directbase.DirectStart

from direct.showbase.DirectObject import DirectObject
from direct.interval.MetaInterval import Sequence
from direct.interval.FunctionInterval import Func
from direct.interval.SoundInterval import SoundInterval


def doPrint(arg):
	print arg


class Test(DirectObject):
	def __init__(self):
		DirectObject.__init__(self)
		
		self.seq = Sequence(Func(doPrint, 'start'),
							SoundInterval(loader.loadSfx(<INSERT ANY AUDIO HERE>)),
							Func(doPrint, 'end')
							)
		
		self.running = False
		self.accept('space', self.onSpace)
		
	
	def onSpace(self):
		if not self.running:
			self.seq.start()
			self.running = True
		else:
			for ival in self.seq:
				if isinstance(ival, SoundInterval):
					ival.finish()
		
		


t = Test()

run()

In fact, ‘end’ will not be printed until the SoundInterval is finished, no matter if I press ‘space’ (and audio playback stops) or not.

Any ideas? Are we doing something wrong?

Yours,
rahdev

To point it up: take

SoundInterval(loader.loadSfx(<ANY AUDIO>), duration = 20) 

-> start Sequence -> press ‘Space’ -> audio playback is stopped almost immediately -> but ‘end’ will only be printed after ~ 20s

Manually advance the time works.
Insert before the finish() line :

self.seq.setT(self.seq.getT()+ival.getDuration()-ival.getT())

You can’t finish a nested interval within a Sequence. You have to finish the parent Sequence directly. Once the Sequence is constructed, you can no longer safely access the component intervals; they’re now controlled entirely by the parent Sequence.

Intervals are intended for static playback only. If you really want this kind of dynamic control, you should consider using the task system instead.

David

@ynjh_jo: It works fine, thanks for this hint!

@drwr: Thank you, too, for your explanation. I think your advice, better using tasks, will be taken into account asap.