diff options
author | Tim Blechmann <timblech@users.sourceforge.net> | 2005-11-20 00:31:44 +0000 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@iem.at> | 2015-10-14 15:11:50 +0200 |
commit | 3f08071defc2b06e68f44bacf04566be120c2a1a (patch) | |
tree | caf42e301c9e9d7c22fe21c49166278127f965fe /bpe.py | |
parent | 057c7afaf898b043245f0972d4f0ca5251afb781 (diff) |
checking in some more abstractions
svn path=/trunk/abstractions/tb/; revision=3984
Diffstat (limited to 'bpe.py')
-rw-r--r-- | bpe.py | 91 |
1 files changed, 91 insertions, 0 deletions
@@ -0,0 +1,91 @@ +# $Id: bpe.py,v 1.1 2005-11-20 00:31:44 timblech Exp $ +# +# Copyright (C) 2005 Tim Blechmann +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + + +import pyext + +def parse_arguments(*args): + duration = args[0] + if duration == 0: + return args[1:] + + length = len(args) + durations = [] + breakpoints = [] + for i in range(1,length): + if i % 2 == 0: + durations.append(args[i]) + else: + breakpoints.append(args[i]) + duration_factor = duration / reduce(lambda x,y: x + y, durations) + + durations = map(lambda x: x*duration_factor, durations) + + ret = [] + + for i in range(len(durations)): + ret.append(breakpoints[i]) + ret.append(durations[i]) + ret[-2] = ret[0] + return ret + +class Bpe(pyext._class): + _inlets = 1 + _outlets = 1 + + def list_1(self, *args): + if args[0] != 0: + self._outlet(1,parse_arguments(*args)) + +class VolBpe(pyext._class): + _inlets = 3 + _outlets = 1 + + def __init__(self, dollar1): + try: + self.duration = 1000 / dollar1 + except: + self.duration = 1000 + self._detach = 1 + self._priority(-20) + + self.bpe = [] + self.running = False + + def list_1(self, *args): + arglist = list(args) + arguments = [self.duration] + arglist + self.bpe = arglist + self._outlet(1,parse_arguments(*arguments)) + if not self.running: + self._outlet(1, None) + self.running = True + + def float_2(self, freq): + self.duration = 1000 / freq; + arguments = self.duration + self.bpe + self._outlet(1,parse_arguments(*arguments)) + + + def float_3(self, switch): + if switch == 0: + self._outlet(1, self.bpe[0], 0, self.bpe[0], self.duration) + else: + self._outlet(1, self.bpe) + |