def __init__(self, parent, pos=(0, 0), size=(300, 200), style=0): wx.Panel.__init__(self, parent, pos=pos, size=size, style=style) box = wx.BoxSizer(wx.VERTICAL) self._curzoom = (0.0, 1.0) self.sndview = SndViewTablePanel(self, None, self._position_callback, self._select_callback) box.Add(self.sndview, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5) self.zoom = HRangeSlider(self, minvalue=0, maxvalue=1, valtype='float', function=self._setZoom, backColour=parent.GetBackgroundColour()) box.Add(self.zoom, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 5) self.SetSizer(box)
def __init__(self, parent, pos=(0, 0), size=(300, 200), style=0): wx.Panel.__init__(self, parent, pos=pos, size=size, style=style) box = wx.BoxSizer(wx.VERTICAL) self._curzoom = (0.0, 1.0) self.sndview = SndViewTablePanel(self, None, self._position_callback, self._select_callback) box.Add(self.sndview, 1, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) self.zoom = HRangeSlider(self, minvalue=0, maxvalue=1, valtype='float', function=self._setZoom, backColour=parent.GetBackgroundColour()) box.Add(self.zoom, 0, wx.EXPAND|wx.LEFT|wx.RIGHT, 5) self.SetSizer(box)
class PyoGuiSndView(wx.Panel): """ Soundfile display. This widget should be used with the SndTable object, which keeps soundfile in memory and computes the waveform to display on the GUI. To create the bridge between the audio memory and the display, the SndTable object must be registered in the PyoGuiSndView object with the setTable(object) method. The SndTable object will automatically call the update() method to refresh the display when the table is modified. :Parent: wx.Panel :Events: EVT_PYO_GUI_SNDVIEW_MOUSE_POSITION Sent when the mouse is moving on the panel with the left button pressed. The `value` attribute of the event will hold the normalized position of the mouse into the sound. For X-axis value, 0.0 is the beginning of the sound and 1.0 is the end of the sound. For the Y-axis, 0.0 is the bottom of the panel and 1.0 is the top. EVT_PYO_GUI_SNDVIEW_SELECTION Sent when a new region is selected on the panel. A new selection is created with a Right-click and drag on the panel. The current selection can be moved with Shift+Right-click and drag. Ctrl+Right-click (Cmd on OSX) remove the selected region. The `value` attribute of the event will hold the normalized selection as a tuple (min, max). 0.0 means the beginning of the sound and 1.0 means the end of the sound. :Args: parent : wx.Window The parent window. pos : wx.Point, optional Window position in pixels. Defaults to (0, 0). size : wx.Size, optional Window size in pixels. Defaults to (300, 200). style : int, optional Window style (see wx.Window documentation). Defaults to 0. """ def __init__(self, parent, pos=(0, 0), size=(300, 200), style=0): wx.Panel.__init__(self, parent, pos=pos, size=size, style=style) box = wx.BoxSizer(wx.VERTICAL) self._curzoom = (0.0, 1.0) self.sndview = SndViewTablePanel(self, None, self._position_callback, self._select_callback) box.Add(self.sndview, 1, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) self.zoom = HRangeSlider(self, minvalue=0, maxvalue=1, valtype='float', function=self._setZoom, backColour=parent.GetBackgroundColour()) box.Add(self.zoom, 0, wx.EXPAND|wx.LEFT|wx.RIGHT, 5) self.SetSizer(box) def _setZoom(self, values=None): if values is None: values = self._curzoom dur = self.sndview.getDur() self.sndview.setBegin(dur * values[0]) self.sndview.setEnd(dur * values[1]) self._curzoom = values self.update() def _position_callback(self, pos): evt = PyoGuiSndViewMousePositionEvent(value=pos) wx.PostEvent(self, evt) def _select_callback(self, selection): selection = (max(0.0, min(selection)), min(max(selection), 1.0)) evt = PyoGuiSndViewSelectionEvent(value=selection) wx.PostEvent(self, evt) def __del__(self): if self.sndview.obj is not None: self.sndview.obj._setViewFrame(None) self.Destroy() def update(self): """ Display updating method. This method is automatically called by the audio memory object (SndTable) when the table is modified. The method setTable(obj) must be used to register the audio memory object. """ wx.CallAfter(self.sndview.setImage) def setTable(self, object): """ Register an audio memory object (SndTable). :Args: object : SndTable object The audio table keeping the sound in memory. """ object._setViewFrame(self) self.sndview.obj = object self.sndview.setBegin(0.0) self.sndview.setEnd(object.getDur(False)) self.sndview.chnls = len(object) self.update() def setSelection(self, start, stop): """ Changes the selected region. This method will trigger a EVT_PYO_GUI_SNDVIEW_SELECTION event with a tuple (start, stop) as value. :Args: start : float The starting point of the selected region. This value must be normalized between 0 and 1 (0 is the beginning of the sound, 1 is the end). stop : float The ending point of the selected region. This value must be normalized between 0 and 1 (0 is the beginning of the sound, 1 is the end). """ self.sndview.setSelection(start, stop) def resetSelection(self): """ Removes the selected region. This method will trigger a EVT_PYO_GUI_SNDVIEW_SELECTION event with a tuple (0.0, 1.0) as value. """ self.sndview.resetSelection()
class PyoGuiSndView(wx.Panel): """ Soundfile display. This widget should be used with the SndTable object, which keeps soundfile in memory and computes the waveform to display on the GUI. To create the bridge between the audio memory and the display, the SndTable object must be registered in the PyoGuiSndView object with the setTable(object) method. The SndTable object will automatically call the update() method to refresh the display when the table is modified. :Parent: wx.Panel :Events: EVT_PYO_GUI_SNDVIEW_MOUSE_POSITION Sent when the mouse is moving on the panel with the left button pressed. The `value` attribute of the event will hold the normalized position of the mouse into the sound. For X-axis value, 0.0 is the beginning of the sound and 1.0 is the end of the sound. For the Y-axis, 0.0 is the bottom of the panel and 1.0 is the top. EVT_PYO_GUI_SNDVIEW_SELECTION Sent when a new region is selected on the panel. A new selection is created with a Right-click and drag on the panel. The current selection can be moved with Shift+Right-click and drag. Ctrl+Right-click (Cmd on OSX) remove the selected region. The `value` attribute of the event will hold the normalized selection as a tuple (min, max). 0.0 means the beginning of the sound and 1.0 means the end of the sound. :Args: parent : wx.Window The parent window. pos : wx.Point, optional Window position in pixels. Defaults to (0, 0). size : wx.Size, optional Window size in pixels. Defaults to (300, 200). style : int, optional Window style (see wx.Window documentation). Defaults to 0. """ def __init__(self, parent, pos=(0, 0), size=(300, 200), style=0): wx.Panel.__init__(self, parent, pos=pos, size=size, style=style) box = wx.BoxSizer(wx.VERTICAL) self._curzoom = (0.0, 1.0) self.sndview = SndViewTablePanel(self, None, self._position_callback, self._select_callback) box.Add(self.sndview, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5) self.zoom = HRangeSlider(self, minvalue=0, maxvalue=1, valtype='float', function=self._setZoom, backColour=parent.GetBackgroundColour()) box.Add(self.zoom, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 5) self.SetSizer(box) def _setZoom(self, values=None): if values is None: values = self._curzoom dur = self.sndview.getDur() self.sndview.setBegin(dur * values[0]) self.sndview.setEnd(dur * values[1]) self._curzoom = values self.update() def _position_callback(self, pos): evt = PyoGuiSndViewMousePositionEvent(value=pos) wx.PostEvent(self, evt) def _select_callback(self, selection): selection = (max(0.0, min(selection)), min(max(selection), 1.0)) evt = PyoGuiSndViewSelectionEvent(value=selection) wx.PostEvent(self, evt) def __del__(self): if self.sndview.obj is not None: self.sndview.obj._setViewFrame(None) self.Destroy() def update(self): """ Display updating method. This method is automatically called by the audio memory object (SndTable) when the table is modified. The method setTable(obj) must be used to register the audio memory object. """ wx.CallAfter(self.sndview.setImage) def setTable(self, object): """ Register an audio memory object (SndTable). :Args: object : SndTable object The audio table keeping the sound in memory. """ object._setViewFrame(self) self.sndview.obj = object self.sndview.setBegin(0.0) self.sndview.setEnd(object.getDur(False)) self.sndview.chnls = len(object) self.update() def setSelection(self, start, stop): """ Changes the selected region. This method will trigger a EVT_PYO_GUI_SNDVIEW_SELECTION event with a tuple (start, stop) as value. :Args: start : float The starting point of the selected region. This value must be normalized between 0 and 1 (0 is the beginning of the sound, 1 is the end). stop : float The ending point of the selected region. This value must be normalized between 0 and 1 (0 is the beginning of the sound, 1 is the end). """ self.sndview.setSelection(start, stop) def resetSelection(self): """ Removes the selected region. This method will trigger a EVT_PYO_GUI_SNDVIEW_SELECTION event with a tuple (0.0, 1.0) as value. """ self.sndview.resetSelection()