Example #1
0
	def __init__(self, controller, parent=None):
		QWidget.__init__(self, parent)
		
		self.controller=controller
		
		self.setupUi(self)
		self.name="Audio"
		
		QObject.connect(
			self.active_checkBox, SIGNAL("stateChanged(int)"),
			self.isActiveChanged
		)
		self.lastTime=0
		self.replayActive=False
		self.ownTimesourceUsed=False

		self.audioQuitter=AudioQuitter()
		QObject.connect(
			self.audioQuitter, SIGNAL("oggEnded()"), self.onOggEnded
		)

		AudioPlayer.audio_initialize(self.audioQuitter)
		
		# populate the output devices combo
		settings = QSettings()
		settings.beginGroup("/plugins/PlayerPlugin/Audio")
		defaultDeviceIndex = settings.value("outputDevice", AudioPlayer.defaultDeviceIndex()).toInt()[0]
		for device in AudioPlayer.devices():
			if device.isOutput:
				self.cboOutputDevice.addItem( "[%s] %s" % (device.api, device.name), QVariant(device.index))
			if device.index == defaultDeviceIndex:
				self.cboOutputDevice.setCurrentIndex( self.cboOutputDevice.count()-1 ) # use last added device
Example #2
0
	def stopReplay(self):
		if self.replayActive:
			AudioPlayer.ogg_closeFile()
			AudioPlayer.audio_stop()
			self.replayActive=False
		
		self.active_checkBox.setEnabled(True)
Example #3
0
	def unload(self):
		AudioPlayer.audio_terminate()

		settings = QSettings()
		settings.beginGroup("/plugins/PlayerPlugin/Audio")
		if self.cboOutputDevice.currentIndex() >= 0:
			device = self.cboOutputDevice.itemData(self.cboOutputDevice.currentIndex()).toInt()[0]
			settings.setValue("outputDevice", device)
Example #4
0
	def updateReplayToTime(self, time, forceSeek=False):
		if self.replayActive:
			needSync=((self.getReplayPosition()-time) > AUDIO_OFF_TOLERANCE)
			newFileLoaded=self.loadCorrectOgg(time)
			
			if newFileLoaded or forceSeek or needSync:
				if self.currentFile!=None:
					AudioPlayer.ogg_seekToTime(time-self.currentFile[1])
		
		self.lastTime=time
Example #5
0
	def getReplayPosition(self):
		if self.replayActive:
			cst=AudioPlayer.audio_getCurrentTime()
			
			#workaround for weird portaudio behaviour
			if self.lastRewindStreamTime==0:
				self.lastRewindStreamTime=cst
				
			rv=cst-self.lastRewindStreamTime+self.lastRewindTime
			return rv
		else:
			return self.lastTime
Example #6
0
	def startReplay(self, fromTime):
		if not self.active_checkBox.isChecked():
			self.active_checkBox.setEnabled(False)
			return
		
		self.stopReplay()
		self.seekReplayToTime(fromTime)
		device = self.cboOutputDevice.itemData(self.cboOutputDevice.currentIndex()).toInt()[0]
		if not AudioPlayer.audio_start(device):
				self.active_checkBox.setChecked(False)
				QMessageBox.critical(None, self.tr("Error"), self.tr("Couldn't start audio replay..."))
		else:
			self.replayActive=True
		self.active_checkBox.setEnabled(False)
Example #7
0
	def loadRecording(self, dataDirectory):
		self.active_checkBox.setChecked(False)
		
		#create list of available ogg files in current recording
		self.dataDirectory=dataDirectory+self.name+"/"
		self.setEnabled(os.path.isdir(self.dataDirectory))
		if not os.path.isdir(self.dataDirectory):
			self.oggFiles=[]
			return
		
		self.oggFiles=[[f,parseAudioFileNameTime(f)] for f in os.listdir(self.dataDirectory) if (f[f.rfind('.'):].lower()==".ogg")]
		self.setEnabled(self.oggFiles!=[])
		if self.oggFiles==[]:
			return
		
		for oggFile in self.oggFiles:
			AudioPlayer.ogg_openFile(str(self.dataDirectory+oggFile[0]))
			oggFile.append(AudioPlayer.ogg_getLength())
			AudioPlayer.ogg_closeFile()
		
		self.active_checkBox.setChecked(True)
		
		self.currentFile=None
		self.replayActive=False
Example #8
0
	def switchToOgg(self, newOgg, onlyIfPlaysUntilTime):
		if (self.currentFile!=newOgg):
			if (self.currentFile!=None):
				AudioPlayer.ogg_closeFile()
			
			if (newOgg!=None):
				AudioPlayer.ogg_openFile(str(self.dataDirectory+newOgg[0]))
				AudioPlayer.ogg_startDecoding()
			
			self.currentFile=newOgg

			return newOgg!=None
		
		return False
Example #9
0
	def seekReplayToTime(self, time):
		self.updateReplayToTime(time, True)
		
		self.lastRewindTime=time
		self.lastRewindStreamTime=AudioPlayer.audio_getCurrentTime()