Pyo 및 WX 라이브러리를 기반으로하는 간단한 신호 생성기를 Python으로 작성합니다.Pyo 발진기 출력을 WX 이벤트에 바인딩
나는 각각에 대한 간단한 튜토리얼을 살펴보고 WX에서 WX 로의 버튼을 성공적으로 바인딩했다. 나는 이제 "오실레이터 1"이라고 표시된 버튼을 눌러 1 초 동안 간단한 사인파 (440Hz에서)를 생성하려고합니다. 그러나 main() 함수가 실행될 때 사인 톤이 재생되고 버튼이 wx 프레임에 표시되는 동안 사인 톤을 다시 트리거 할 수 없습니다. 이 두 가지 증상은 모두 원하지 않습니다.
사인 어조는 프로그램 실행 즉시 왜 재생됩니까? 왜 FirstOSC 버튼이 작동하지 않는 것입니까?
import wx
from pyo import *
import time
pyoServer = Server().boot()
pyoServer.start()
class MainWindow(wx.Frame):
def __init__(self,parent,title):
wx.Frame.__init__(self,parent,title=title, size = (640,640))
self.CreateStatusBar() # A StatusBar in the bottom of the window
# Signal Generator controls
oscillator = SoundOutput()
firstOSC = wx.Button(self, wx.ID_YES,"Oscillator 1 " + str(oscillator.str_osc1State))
self.Bind(wx.EVT_BUTTON, oscillator.OnOff1(440), firstOSC)
#Menus
filemenu = wx.Menu()
menuExit = filemenu.Append(wx.ID_EXIT,"&Exit","Terminate the program")
menuBar = wx.MenuBar()
menuBar.Append(filemenu,"&File")
self.SetMenuBar(menuBar)
self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
self.Show(True)
def OnExit(self,e):
self.Close(True)
class SoundOutput(object):
def __init__(self):
self.osc1State = False
self.str_osc1State = "Off"
self.a = Sine(440, 0, 0.1)
def OnOff1(self, frequency):
self.a.freq = frequency
self.a.out()
time.sleep(1)
self.osc1State = True
def Main():
app = wx.App(False)
frame = MainWindow(None,"Signal Generator")
app.MainLoop()