def open_file(self): if self.filename is None: self.filename = QFileDialog.getOpenFileName( self, 'Open file', '/home')[0] self.audio_parts = split_audiofile(self.filename) self.current_audiofile_pos = 0 self.audio = Audio() self.audio.from_wav(self.audio_parts[self.current_audiofile_pos]) self.dense = 1e-100 self.xdata = np.linspace( 0, len(self.audio.audio_segment) / self.audio.rate, num=len(self.audio.audio_segment * self.dense)) self.ydata = self.audio.audio_segment self.canvas.axes.clear() self._plot_ref = None self.update_plot()
def runMusic(self): if self.menumusic and not self.song.isPlaying(): #re-randomize if self.files: i = random.randint(0, len(self.files) - 1) filename = self.files[i] sound = os.path.join("themes", self.themename, "sounds", filename) self.menumusic = True self.engine.menuMusic = True self.song = Audio.Music(self.engine.resource.fileName(sound)) self.song.setVolume( self.engine.config.get("audio", "menu_volume")) self.song.play(0) else: self.menumusic = False self.engine.menuMusic = False
def __init__(self, engine, controlnum, samprate=44100): Task.__init__(self) self.engine = engine self.controlnum = controlnum devnum = self.engine.input.controls.micDevice[controlnum] if devnum == -1: devnum = None self.devname = pa.get_default_input_device_info()['name'] else: self.devname = pa.get_device_info_by_index(devnum)['name'] self.mic = pa.open(samprate, 1, pyaudio.paFloat32, input=True, input_device_index=devnum, start=False) self.analyzer = pypitch.Analyzer(samprate) self.mic_started = False self.lastPeak = 0 self.detectTaps = True self.tapStatus = False self.tapThreshold = -self.engine.input.controls.micTapSensitivity[ controlnum] self.passthroughQueue = [] passthroughVolume = self.engine.input.controls.micPassthroughVolume[ controlnum] if passthroughVolume > 0.0: Log.debug( 'Microphone: creating passthrough stream at %d%% volume' % round(passthroughVolume * 100)) self.passthroughStream = Audio.MicrophonePassthroughStream( engine, self) self.passthroughStream.setVolume(passthroughVolume) else: Log.debug('Microphone: not creating passthrough stream') self.passthroughStream = None
class Window(QMainWindow, Ui_MainWindow): def __init__(self, parent=None): super().__init__(parent) self.setupUi(self) self.canvas = MplCanvas(self, width=5, height=4, dpi=100) self.coordinates = [] self.filename = None self.audio_parts = [] self.current_audiofile = None self.current_audiofile_pos = 0 self.open_file() toolbar = NavigationToolbar(self.canvas, self) layout = QVBoxLayout() layout.addWidget(toolbar) layout.addWidget(self.canvas) widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget) self.show() self.connect_signals_slots() def update_plot(self): self.ydata = self.audio.audio_segment self.xdata = np.linspace( 0, len(self.audio.audio_segment) / self.audio.rate, num=len(self.audio.audio_segment * self.dense)) if self._plot_ref is None: plot_refs = self.canvas.axes.plot(self.xdata, self.ydata, 'b') self._plot_ref = plot_refs[0] else: self._plot_ref.set_ydata(self.ydata) self.canvas.draw() def connect_signals_slots(self): self.action_Exit.triggered.connect(self.close) self.action_About.triggered.connect(self.about) self.actionS_wap.triggered.connect(self.swap) self.action_Delete.triggered.connect(self.delete) self.actionChange_Pitc_h.triggered.connect(self.change_pitch) self.actionChange_Volume.triggered.connect(self.change_volume) self.actionChange_S_peed.triggered.connect(self.change_speed) self.actionFade_In.triggered.connect(self.fade_in) self.actionFade_Out.triggered.connect(self.fade_out) self.actionPlay.triggered.connect(self.play) self.action_Open.triggered.connect(self.open_file) self.action_Save_2.triggered.connect(self.save_file) self.action_Save.triggered.connect(self.save_file) self.action_3.triggered.connect(self.prev_audio) self.action_2.triggered.connect(self.next_audio) def about(self): QMessageBox.about( self, "About AudioEditor", """<p>A simple audio editor app built with:</p> <p>- PyQt</p> <p>- Qt Designer</p> <p>- PyDub</p> <p>- Matplotlib</p>""") def play(self): dialog = Play(self) dialog.exec() def onclick_swap(self, event): self.coordinates.append(event.xdata) self.canvas.axes.axvline(x=event.xdata, c='r') if len(self.coordinates) == 4: dialog = Swap(self) dialog.exec() self.coordinates = [] self.canvas.mpl_disconnect(self.swap_canvas_onclick) self.canvas.axes.clear() self._plot_ref = None self.update_plot() def swap(self): self.swap_canvas_onclick = self.canvas.mpl_connect( 'button_press_event', self.onclick_swap) def onclick_delete(self, event): self.coordinates.append(event.xdata) self.canvas.axes.axvline(x=event.xdata, c='r') if len(self.coordinates) == 2: dialog = Delete(self) dialog.exec() self.coordinates = [] self.canvas.mpl_disconnect(self.delete_canvas_onclick) self.canvas.axes.clear() self._plot_ref = None self.update_plot() def delete(self): self.delete_canvas_onclick = self.canvas.mpl_connect( 'button_press_event', self.onclick_delete) def change_pitch(self): dialog = ChangePitch(self) dialog.exec() value = dialog.spinBox.value() self.audio = self.audio.change_pitch(value) def change_volume(self): dialog = ChangeVolume(self) dialog.exec() value = dialog.doubleSpinBox.value() self.audio.change_volume(value) self._plot_ref = None self.update_plot() def change_speed(self): dialog = ChangeSpeed(self) dialog.exec() value = dialog.doubleSpinBox.value() self.audio.change_speed(value) def onclick_fade_in(self, event): self.coordinates.append(event.xdata) self.canvas.axes.axvline(x=event.xdata, c='r') if len(self.coordinates) == 1: dialog = FadeIn(self) dialog.exec() self.coordinates = [] self.canvas.mpl_disconnect(self.fade_in_onclick) self.canvas.axes.clear() self._plot_ref = None self.update_plot() def fade_in(self): self.fade_in_onclick = self.canvas.mpl_connect('button_press_event', self.onclick_fade_in) def onclick_fade_out(self, event): self.coordinates.append(event.xdata) self.canvas.axes.axvline(x=event.xdata, c='r') if len(self.coordinates) == 1: dialog = FadeOut(self) dialog.exec() self.coordinates = [] self.canvas.mpl_disconnect(self.fade_out_onclick) self.canvas.axes.clear() self._plot_ref = None self.update_plot() def fade_out(self): self.fade_out_onclick = self.canvas.mpl_connect( 'button_press_event', self.onclick_fade_out) def next_audio(self): self.current_audiofile_pos = min(self.current_audiofile_pos + 1, len(self.audio_parts) - 1) self.save_part() self.open_file() def prev_audio(self): self.current_audiofile_pos = max(self.current_audiofile_pos - 1, 0) self.save_part() self.open_file() def open_file(self): if self.filename is None: self.filename = QFileDialog.getOpenFileName( self, 'Open file', '/home')[0] self.audio_parts = split_audiofile(self.filename) self.current_audiofile_pos = 0 self.audio = Audio() self.audio.from_wav(self.audio_parts[self.current_audiofile_pos]) self.dense = 1e-100 self.xdata = np.linspace( 0, len(self.audio.audio_segment) / self.audio.rate, num=len(self.audio.audio_segment * self.dense)) self.ydata = self.audio.audio_segment self.canvas.axes.clear() self._plot_ref = None self.update_plot() def save_part(self): filename = self.audio_parts[self.current_audiofile_pos] self.audio.save_to_wav(filename) def save_file(self): self.save_part() filename = QFileDialog.getSaveFileName(self, 'Open file', '/home')[0] join_audiofile(self.audio_parts, filename)
font = GUI.FontType("res/font/arial") myGUI = GUI.GUI() div1 = GUI.GUIDivision((0, 0, 1, 1)) div1.display = True text = font.constructGuiText("Hello World!", 1, (0, 0), 0.15, [1, 0, 0]) div1.addComponent(text) button = GUI.GUIButton((0, 0, 0.1, 0.05), (0, 0.7, 0.8), window) div1.addComponent(button) # div2 = GUI.GUIDivision(0, 0, 1, 1) # text2 = GUI.GUIText(0, 0, 0, 0, 1, (1, 1, 1)) # div2.addComponent(text1) myGUI.addComponent(div1) myGUI.setup() # AUDIO audioContext = Audio.createContext() Audio.setListenerData(0, 0, 0) buffer = Audio.loadSound("res/sounds/bounce.wav") source = Audio.Source() glClearColor(0.0, 0.0, 0.0, 1.0) while not window.shouldClose(): window.startFrame() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) cam.handleKeyboardInput() masterRenderer.renderScene(cam, entities, [island], lights) masterRenderer.renderGUI(myGUI) if window.getKeyState(glfw.KEY_M) == glfw.PRESS:
def __init__(self, engine): self.engine = engine self.logClassInits = Config.get("game", "log_class_inits") if self.logClassInits == 1: Log.debug("MainMenu class init (MainMenu.py)...") self.time = 0.0 self.nextLayer = None self.visibility = 0.0 self.active = False self.showStartupMessages = False self.gfxVersionTag = Config.get("game", "gfx_version_tag") self.chosenNeck = Config.get("game", "default_neck") exists = 0 if engine.loadImgDrawing( self, "ok", os.path.join("necks", self.chosenNeck + ".png")): exists = 1 elif engine.loadImgDrawing( self, "ok", os.path.join("necks", "Neck_" + self.chosenNeck + ".png")): exists = 1 #MFH - fallback logic now supports a couple valid default neck filenames #MFH - check for Neck_1 if exists == 0: if engine.loadImgDrawing(self, "ok", os.path.join("necks", "Neck_1.png")): Config.set("game", "default_neck", "1") Log.warn( "Default chosen neck not valid; fallback Neck_1.png forced." ) exists = 1 #MFH - check for defaultneck if exists == 0: if engine.loadImgDrawing(self, "ok", os.path.join("necks", "defaultneck.png")): Log.warn( "Default chosen neck not valid; fallback defaultneck.png forced." ) Config.set("game", "default_neck", "defaultneck") exists = 1 else: Log.error( "Default chosen neck not valid; fallbacks Neck_1.png and defaultneck.png also not valid!" ) #Get theme self.theme = self.engine.data.theme self.themeCoOp = self.engine.data.themeCoOp self.themename = self.engine.data.themeLabel self.useSoloMenu = self.engine.theme.use_solo_submenu allowMic = True self.menux = self.engine.theme.menuPos[0] self.menuy = self.engine.theme.menuPos[1] self.rbmenu = self.engine.theme.menuRB #MFH self.main_menu_scale = self.engine.theme.main_menu_scaleVar self.main_menu_vspacing = self.engine.theme.main_menu_vspacingVar if not self.engine.loadImgDrawing( self, "background", os.path.join("themes", self.themename, "menu", "mainbg.png")): self.background = None self.engine.loadImgDrawing( self, "BGText", os.path.join("themes", self.themename, "menu", "maintext.png")) self.engine.loadImgDrawing( self, "optionsBG", os.path.join("themes", self.themename, "menu", "optionsbg.png")) self.engine.loadImgDrawing( self, "optionsPanel", os.path.join("themes", self.themename, "menu", "optionspanel.png")) #racer: added version tag if self.gfxVersionTag or self.engine.theme.versiontag == True: if not self.engine.loadImgDrawing( self, "version", os.path.join("themes", self.themename, "menu", "versiontag.png")): if not self.engine.loadImgDrawing( self, "version", "versiontag.png" ): #falls back on default versiontag.png in data\ folder self.version = None else: self.version = None #myfingershurt: random main menu music function, menu.ogg and menuXX.ogg (any filename with "menu" as the first 4 letters) self.files = None filepath = self.engine.getPath( os.path.join("themes", self.themename, "sounds")) if os.path.isdir(filepath): self.files = [] allfiles = os.listdir(filepath) for name in allfiles: if os.path.splitext(name)[1] == ".ogg": if string.find(name, "menu") > -1: self.files.append(name) if self.files: i = random.randint(0, len(self.files) - 1) filename = self.files[i] sound = os.path.join("themes", self.themename, "sounds", filename) self.menumusic = True engine.menuMusic = True self.song = Audio.Music(self.engine.resource.fileName(sound)) self.song.setVolume(self.engine.config.get("audio", "menu_volume")) self.song.play(0) #no loop else: self.menumusic = False self.opt_text_color = self.engine.theme.opt_text_colorVar self.opt_selected_color = self.engine.theme.opt_selected_colorVar trainingMenu = [ (_("Tutorials"), self.showTutorial), (_("Practice"), lambda: self.newLocalGame(mode1p=1)), ] self.opt_bkg_size = [float(i) for i in self.engine.theme.opt_bkg_size] self.opt_text_color = self.engine.theme.hexToColor( self.engine.theme.opt_text_colorVar) self.opt_selected_color = self.engine.theme.hexToColor( self.engine.theme.opt_selected_colorVar) if self.BGText: strCareer = "" strQuickplay = "" strSolo = "" strMultiplayer = "" strTraining = "" strSettings = "" strQuit = "" else: strCareer = "Career" strQuickplay = "Quickplay" strSolo = "Solo" strMultiplayer = "Multiplayer" strTraining = "Training" strSettings = "Settings" strQuit = "Quit" multPlayerMenu = [ (_("Face-Off"), lambda: self.newLocalGame(players=2, maxplayers=4)), (_("Pro Face-Off"), lambda: self.newLocalGame(players=2, mode2p=1, maxplayers=4)), (_("Party Mode"), lambda: self.newLocalGame(mode2p=2)), (_("FoFiX Co-Op"), lambda: self.newLocalGame( players=2, mode2p=3, maxplayers=4, allowMic=allowMic)), (_("RB Co-Op"), lambda: self.newLocalGame( players=2, mode2p=4, maxplayers=4, allowMic=allowMic)), (_("GH Co-Op"), lambda: self.newLocalGame(players=2, mode2p=5, maxplayers=4)), (_("GH Battle"), lambda: self.newLocalGame(players=2, mode2p=6, allowDrum=False) ), #akedrou- so you can block drums ] if not self.useSoloMenu: mainMenu = [ (strCareer, lambda: self.newLocalGame(mode1p=2, allowMic=allowMic)), (strQuickplay, lambda: self.newLocalGame(allowMic=allowMic)), ((strMultiplayer, "multiplayer"), multPlayerMenu), ((strTraining, "training"), trainingMenu), ((strSettings, "settings"), self.settingsMenu), (strQuit, self.quit), ] else: soloMenu = [ (_("Solo Tour"), lambda: self.newLocalGame(mode1p=2, allowMic=allowMic)), (_("Quickplay"), lambda: self.newLocalGame(allowMic=allowMic)), ] mainMenu = [ ((strSolo, "solo"), soloMenu), ((strMultiplayer, "multiplayer"), multPlayerMenu), ((strTraining, "training"), trainingMenu), ((strSettings, "settings"), self.settingsMenu), (strQuit, self.quit), ] w, h, = self.engine.view.geometry[2:4] self.menu = Menu(self.engine, mainMenu, onClose=lambda: self.engine.view.popLayer(self), pos=(self.menux, .75 - (.75 * self.menuy))) engine.mainMenu = self #Points engine.mainMenu to the one and only MainMenu object instance ## whether the main menu has come into view at least once self.shownOnce = False