def save(self, ftype='', dtype='int16'): """Save new data to file, return the size of the saved file (or None). The file format is inferred from the filename extension, e.g., `flac`. This will be overridden by the `ftype` if one is provided; defaults to `wav` if nothing else seems reasonable. The optional `dtype` (e.g., `int16`) can be any of the sample types supported by `pyo`. """ if self.file_in or not self.count: return self.save_fmt = os.path.splitext(self.filename)[1].lstrip('.') fmt = ftype or self.save_fmt or 'wav' if not self.filename.endswith('.' + fmt): self.filename += '.' + fmt # Save the recording (continuous, non-chunked): end_index = int(self.elapsed * self.rate) # ~samples if end_index < self._wholetable.size: dataf = np.asarray(self._wholetable.getTable()[:end_index]) samples_to_file(dataf, self.rate, self.filename, fmt=fmt, dtype=dtype) self.sec = pyo.sndinfo(self.filename)[1] else: table_to_file(self._wholetable, self.filename, fmt=fmt, dtype=dtype) self.filesize = os.path.getsize(self.filename) return self.filesize
def __init__(self, sec=None, source='rec.wav', start=0, stop=-1, rate=44100): if type(source) in [np.ndarray]: sec = len(source) / rate elif os.path.isfile(source): sec = pyo.sndinfo(source)[1] config = {'start': start, 'stop': stop} super(Player, self).__init__(sec, file_in=source, **config)
def OnDropFiles(self, x, y, filenames): x, y = self.grid.CalcUnscrolledPosition(x, y) col = self.grid.XToCol(x) row = self.grid.YToRow(y) if row > -1 and col == ID_COL_FILENAME: filename = filenames[0] if sndinfo(filename) is not None: self.grid.copyToSoundsFolder(filename) self.grid.setSelRow(row) self.grid.loadSound(os.path.basename(filename))
def table_from_file(file_in, start=0, stop=-1): """Read data from files, any pyo format, returns (rate, pyo SndTable) """ table = pyo.SndTable() try: table.setSound(file_in, start=start, stop=stop) except TypeError: msg = 'bad file `{0}`, or format not supported'.format(file_in) raise PyoFormatException(msg) rate = pyo.sndinfo(file_in)[2] return rate, table
def __init__(self, id, filename, loopmode=0, transpo=1, gain=0, playing=0, directout=True, startpoint=0, endpoint=-1, crossfade=5, channel=0): interpTime = QLiveLib.getVar("globalInterpTime") self.id = id self.filename = filename sndfolder = os.path.join(QLiveLib.getVar("projectFolder"), "sounds") info = sndinfo(os.path.join(sndfolder, self.filename)) if info is None: self.valid = False self.duration = -1 self.sndchnls = -1 else: self.valid = True self.duration = info[1] self.sndchnls = info[3] self.loopmode = loopmode self.transpo = transpo self.gain = gain self.playing = playing self.directout = directout self.startpoint = startpoint self.endpoint = self.duration self.crossfade = crossfade self.channel = channel self.transpox = interpTime self.gainx = interpTime self.transpoDict = None self.gainDict = None self.showInterp = 0 self.playerRef = None self.transpoAutoWindow = None self.gainAutoWindow = None self.cues = {} self.copied = {} currentCue = QLiveLib.getVar("CuesPanel").getCurrentCue() self.addCue(0) self.addCue(currentCue)