Source code for csengine.stack

from .globals import ActivePlugin
from .utility import DebugUtility
from . import globals
import time
import cv2


[docs] class Stack: audioChannelBusy = [False] * 3 shutdown = False def __init__(self, slides, name): self.stackList = [] self.stackLimit = 3 self.name = name self.slidesObj = slides self.audioChannelBusy = [False] * 3 self.customName = False
[docs] def dropFrame(self): for plugin in self.stackList: plugin.dropFrame()
[docs] def getFrame(self, frame): #benchmarking implemented: #calculate the duration in ms that each plugin's getframe function uses bench = [] if self.shutdown: return frame returnFrame = frame for plugin in self.stackList: if plugin.requiresRGB: returnFrame = cv2.cvtColor(returnFrame, cv2.COLOR_RGBA2RGB) tic = time.perf_counter() returnFrame = plugin.getFrame(returnFrame) toc = time.perf_counter() bench.append(toc - tic) # add alpha channel if required! if returnFrame.shape[2] == 3: returnFrame = cv2.cvtColor(returnFrame, cv2.COLOR_RGB2RGBA) return returnFrame, bench
[docs] def getAudio(self, chunk): if self.shutdown: return for plugin in self.stackList: plugin.getAudio(chunk)
[docs] def addToStack(self, pluginObject): # If the plugin Object already exists in the current stack then return 0 and do nothing for item in self.stackList: if type(pluginObject) == type(item): return True, item # if the plugin object is not in the list and the stack is not full then create new instance and add it if len(self.stackList) < self.stackLimit: pluginClass = pluginObject.__class__ new_plugin = pluginClass(normalBG=pluginObject.normalBG, downBG=pluginObject.downBG, controllerBG=pluginObject.controllerBG, name=pluginObject.name, description=pluginObject.description, tags=pluginObject.tags_raw, info_image=pluginObject.infoImagePath, icon=pluginObject.iconImage, plugin_path=pluginObject.plugin_path, plugin_name=pluginObject.plugin_name, type=pluginObject.type, platform=pluginObject.platform, stackable=pluginObject.stackable) new_plugin.originalInstance = pluginObject # Add Audio Channel foundFreeChannel = False channelCount = 0 for i, channel in enumerate(self.audioChannelBusy): if channel == False: foundFreeChannel = True self.audioChannelBusy[i] = True DebugUtility.Log("Using Free Audio Channel " + str(i)) break channelCount+=1 if foundFreeChannel: new_plugin.audioOverlayChannel = self.slidesObj.overlayAudioChannels[channelCount] new_plugin.writerEvent.set() if new_plugin.audioReRoute: globals.AUDIO_THREAD.setReRoute(True, channelCount) self.stackList.append(new_plugin) self.updateStackButtons() return True, new_plugin else: # if stack is full return False return False, None
[docs] def removeFromStack(self, pluginObject): # If the plugin Object already exists in the current stack then remove it pluginType = type(pluginObject) globals.AUDIO_THREAD.setReRoute(False) for item in self.stackList: if pluginType == type(item): # Remove Audio Channel from plugin audioChannel = item.audioOverlayChannel.channelNr item.audioOverlayChannel = None item.writerEvent.set() self.audioChannelBusy[audioChannel] = False self.stackList.remove(item) self.updateStackButtons() return True else: if item.audioReRoute: chNr = item.audioOverlayChannel.channelNr globals.AUDIO_THREAD.setReRoute(True, chNr) return False
[docs] def openSelectedController(self, index): if index >= 0 and index < len(self.stackList): if self.stackList[index]: self.stackList[index].showController()
[docs] def updateStackButtons(self): for ctr in range(self.stackLimit): # Disable all if globals.STACK_BUTTONS: globals.STACK_BUTTONS[ctr].disabled = True globals.STACK_BUTTONS[ctr].background_normal = "./CommonMedia/emptyIcon.png" globals.STACK_BUTTONS[ctr].background_disabled_normal = "./CommonMedia/emptyIcon.png" if globals.STACK_BUTTONS_SL: globals.STACK_BUTTONS_SL[ctr].disabled = True globals.STACK_BUTTONS_SL[ctr].background_normal = "./CommonMedia/emptyIcon.png" globals.STACK_BUTTONS_SL[ctr].background_disabled_normal = "./CommonMedia/emptyIcon.png" ctr = 0 for item in self.stackList: # Enable active ones if globals.STACK_BUTTONS: globals.STACK_BUTTONS[ctr].disabled = False globals.STACK_BUTTONS[ctr].background_normal = str(item.iconImage) globals.STACK_BUTTONS[ctr].background_down = str(item.iconImage) if globals.STACK_BUTTONS_SL: globals.STACK_BUTTONS_SL[ctr].disabled = False globals.STACK_BUTTONS_SL[ctr].background_normal = str(item.iconImage) globals.STACK_BUTTONS_SL[ctr].background_down = str(item.iconImage) ctr += 1 if globals.STACK_BUTTONS: globals.ACTIVE_SLIDE_NAME.text = self.name if globals.STACK_BUTTONS_SL: globals.ACTIVE_SLIDE_NAME_SL.text = self.name