diff options
author | James <olpc@localhost.localdomain> | 2007-02-20 00:14:18 (GMT) |
---|---|---|
committer | James <olpc@localhost.localdomain> | 2007-02-20 00:14:18 (GMT) |
commit | f172a86bf7a1d0328dcda10ea06761fe4cb70522 (patch) | |
tree | a0c46c94a04890570dd4185eef67ec55a36b97c9 | |
parent | 5a183c571cb4d7074d994a82c0f889efde730411 (diff) |
sound feedback on note edit, global singleton csoundclient
-rw-r--r-- | Edit/MainWindow.py | 10 | ||||
-rw-r--r-- | Edit/NoteInterface.py | 25 | ||||
-rw-r--r-- | Player/KeyboardStandAlone.py | 31 | ||||
-rw-r--r-- | Player/RythmGenerator.py | 2 | ||||
-rw-r--r-- | Player/RythmPlayer.py | 16 | ||||
-rw-r--r-- | Player/StandalonePlayer.py | 29 | ||||
-rw-r--r-- | SynthLab/SynthLabWindow.py | 6 | ||||
-rwxr-xr-x | TamTam.py | 33 | ||||
-rw-r--r-- | Util/CSoundClient.py | 197 |
9 files changed, 109 insertions, 240 deletions
diff --git a/Edit/MainWindow.py b/Edit/MainWindow.py index 5fe3ecd..55df13c 100644 --- a/Edit/MainWindow.py +++ b/Edit/MainWindow.py @@ -3,7 +3,11 @@ pygtk.require( '2.0' ) import gtk import gobject + from Util.ThemeWidgets import * +from Util.Profiler import TP +from Util.NoteDB import NoteDB +from Util.CSoundClient import new_csound_client import time @@ -17,11 +21,9 @@ import Config from Edit.MixerWindow import MixerWindow from Generation.GenerationConstants import GenerationConstants from Generation.GenerationParametersWindow import GenerationParametersWindow -from Util.NoteDB import NoteDB from Edit.TrackInterface import TrackInterface, TrackInterfaceParasite from Edit.TuneInterface import TuneInterface, TuneInterfaceParasite -from Util.Profiler import TP from Generation.Generator import generator1, variate @@ -30,8 +32,8 @@ from Generation.Generator import generator1, variate #----------------------------------- class MainWindow( gtk.EventBox ): - def __init__( self, CSoundClient ): - self.csnd = CSoundClient + def __init__( self ): + self.csnd = new_csound_client() def init_data( ): self._data = {} diff --git a/Edit/NoteInterface.py b/Edit/NoteInterface.py index 90a941e..6b0a8c9 100644 --- a/Edit/NoteInterface.py +++ b/Edit/NoteInterface.py @@ -5,6 +5,7 @@ import gtk import Config from Util.NoteDB import PARAMETER +from Util.CSoundClient import new_csound_client class NoteInterface: @@ -128,11 +129,20 @@ class NoteInterface: self.basePitch = self.note.cs.pitch self.baseDuration = self.note.cs.duration - def updateSampleNote( self, pitch ): - return + def playSampleNote( self, full=True ): + secs_per_tick = 0.025 + csnd = new_csound_client() - def clearSampleNote( self ): - return + if full: + onset = self.note.cs.onset + self.note.cs.onset = 0 + csnd.play( self.note.cs, 0.024) + self.note.cs.onset = onset + else: + (onset,duration) = ( self.note.cs.onset, self.note.cs.duration) + ( self.note.cs.onset, self.note.cs.duration) = (0, 10) + csnd.play( self.note.cs, 0.024) + ( self.note.cs.onset, self.note.cs.duration) = (onset,duration) #======================================================= # Events @@ -175,7 +185,7 @@ class NoteInterface: self.potentialDeselect = True else: emitter.selectNotes( { self.note.track: [ self ] } ) - self.updateSampleNote( self.note.cs.pitch ) + self.playSampleNote( ) percent = eX/self.width if percent < 0.3: emitter.setCurrentAction( "note-drag-onset", self ) @@ -190,7 +200,7 @@ class NoteInterface: self.potentialDeselect = False emitter.deselectNotes( { self.note.track: [ self ] } ) - self.clearSampleNote() + self.playSampleNote() emitter.doneCurrentAction() @@ -207,6 +217,7 @@ class NoteInterface: if dp != self.lastDragP: self.lastDragP = dp stream += [ self.note.id, self.basePitch + dp ] + self.playSampleNote(False) def noteDragDuration( self, dd, stream ): self.potentialDeselect = False @@ -223,7 +234,7 @@ class NoteInterface: self.lastDragP = 0 self.lastDragD = 0 - self.clearSampleNote() + self.playSampleNote() def noteDecOnset( self, step, leftBound, stream ): if self.selected: diff --git a/Player/KeyboardStandAlone.py b/Player/KeyboardStandAlone.py index d273272..1848971 100644 --- a/Player/KeyboardStandAlone.py +++ b/Player/KeyboardStandAlone.py @@ -5,14 +5,15 @@ import gtk import Config #TODO: this is a suprising dependency... what's up?? from Generation.GenerationConstants import GenerationConstants +from Util.NoteDB import Note from Util.CSoundNote import CSoundNote -from Util.Clooper.sclient import sc_loop_getTick +from Util.CSoundClient import new_csound_client KEY_MAP_PIANO = Config.KEY_MAP_PIANO class KeyboardStandAlone: - def __init__( self, client, recordingFunction, adjustDurationFunction, getCurrentTick, getPlayState ): - self.csnd = client + def __init__( self, recordingFunction, adjustDurationFunction, getCurrentTick, getPlayState ): + self.csnd = new_csound_client() self.recording = recordingFunction self.adjustDuration = adjustDurationFunction # self.getCurrentTick = getCurrentTick @@ -76,10 +77,11 @@ class KeyboardStandAlone: fullDuration = False, instrument = instrument, instrumentFlag = instrument, - reverbSend = self.reverb) - self.key_dict[key].playNow(0.3) + reverbSend = self.reverb) + self.csnd.play(self.key_dict[key], 0.3) + #self.key_dict[key].playNow(0.3) if self.getPlayState(): - recOnset = sc_loop_getTick() / 3 + recOnset = self.csnd.loopGetTick() / 3 self.onset_dict[key] = recOnset self.recording( CSoundNote( onset = recOnset, @@ -98,16 +100,15 @@ class KeyboardStandAlone: key = event.hardware_keycode if KEY_MAP_PIANO.has_key(key): - if Config.INSTRUMENTS[ self.key_dict[key].instrument].csoundInstrumentId == Config.INST_TIED: - self.key_dict[key].duration = .5 - self.key_dict[key].decay = 0.7 - self.key_dict[key].amplitude = 1 - self.key_dict[key].playNow(0.3) + csnote = self.key_dict[key] + if Config.INSTRUMENTS[ csnote.instrument].csoundInstrumentId == Config.INST_TIED: + csnote.duration = .5 + csnote.decay = 0.7 + csnote.amplitude = 1 + self.csnd.play(csnote, 0.3) if self.getPlayState(): - self.adjustDuration(self.key_dict[key].pitch, self.onset_dict[key]) - del self.key_dict[key] - else: - del self.key_dict[key] + self.adjustDuration(csnote.pitch, self.onset_dict[key]) + del self.key_dict[key] if self.getPlayState(): if self.onset_dict.has_key(key): del self.onset_dict[key] diff --git a/Player/RythmGenerator.py b/Player/RythmGenerator.py index b917b84..103b905 100644 --- a/Player/RythmGenerator.py +++ b/Player/RythmGenerator.py @@ -6,7 +6,7 @@ from Util.CSoundNote import CSoundNote from Generation.GenerationConstants import GenerationConstants from Player.GenRythm import GenRythm -def generator( instrument, nbeats, regularity, reverbSend, client ): +def generator( instrument, nbeats, regularity, reverbSend ): def makePitchSequence(length, drumPitch): pitchSequence = [] diff --git a/Player/RythmPlayer.py b/Player/RythmPlayer.py index c4fca49..8b339e9 100644 --- a/Player/RythmPlayer.py +++ b/Player/RythmPlayer.py @@ -5,17 +5,17 @@ import gobject import time import Config from Util.CSoundNote import CSoundNote -from Util.Clooper.sclient import sc_loop_getTick +from Util.CSoundClient import new_csound_client class RythmPlayer: - def __init__( self, client, recordButtonState ): + def __init__( self, recordButtonState ): self.notesList = [] self.sequencer = [] self.pitchs = [] self.tempo = 120 self.tickDuration = 60. / self.tempo / 12. self.tick = 15 - self.csnd = client + self.csnd = new_csound_client() self.sequencerPlayback = 0 self.startLooking = 0 self.recordState = 0 @@ -24,9 +24,6 @@ class RythmPlayer: self.beat = 4 self.playState = 0 - def getCurrentTick( self ): - return sc_loop_getTick() - def setTempo( self, tempo ): self.tempo = tempo self.tickDuration = 60. / self.tempo / 12. @@ -65,7 +62,7 @@ class RythmPlayer: def adjustDuration( self, pitch, onset ): if pitch in self.pitchs: - offset = self.getCurrentTick() / 3 + offset = self.csnd.loopGetTick() / 3 for note in self.sequencer: if note.pitch == pitch and note.onset == onset: if offset > note.onset: @@ -77,8 +74,9 @@ class RythmPlayer: self.pitchs.remove( pitch ) def handleClock( self ): - if self.tick != self.getCurrentTick() / 3: - self.tick = self.getCurrentTick() / 3 + t = self.csnd.loopGetTick() / 3 + if self.tick != t: + self.tick = t # if self.sequencer and self.sequencerPlayback: # for note in self.sequencer: # if self.realTick[note.onset] == self.tick: diff --git a/Player/StandalonePlayer.py b/Player/StandalonePlayer.py index 7c22c47..cdbeeab 100644 --- a/Player/StandalonePlayer.py +++ b/Player/StandalonePlayer.py @@ -13,6 +13,8 @@ from Util.ThemeWidgets import * from Util.Credits import Credits #from Util.NoteLooper import NoteLooper from Util.CSoundNote import CSoundNote +from Util.NoteDB import Note +from Util.CSoundClient import new_csound_client from Player.KeyboardStandAlone import KeyboardStandAlone from Player.RythmPlayer import RythmPlayer @@ -24,11 +26,11 @@ Tooltips = Config.Tooltips class StandAlonePlayer( gtk.EventBox ): - def __init__(self, client): + def __init__(self): gtk.EventBox.__init__( self) self.set_border_width(Config.MAIN_WINDOW_PADDING) - self.csnd = client + self.csnd = new_csound_client() self.instrument = self.getInstrumentList()[0] self.timeout_ms = 50 @@ -38,7 +40,7 @@ class StandAlonePlayer( gtk.EventBox ): self.beat = 4 self.tempo = Config.PLAYER_TEMPO self.rythmInstrument = 'drum1kit' - self.rythmPlayer = RythmPlayer(self.csnd, self.recordStateButton) + self.rythmPlayer = RythmPlayer(self.recordStateButton) self.regenerate() self.csnd.loopSetTempo(self.tempo) self.notesList = [] @@ -333,7 +335,6 @@ class StandAlonePlayer( gtk.EventBox ): self.synthLabWindow =None self.synthLabWindow = SynthLabWindow( - self.csnd, {'lab1':86, 'lab2':87, 'lab3':88, 'lab4':89}[data], self.closeSynthLab) self.synthLabWindow.show_all() @@ -349,10 +350,15 @@ class StandAlonePlayer( gtk.EventBox ): for l in ll: rval += l return rval - self.notesList = [(x.onset, x) for x in flatten( generator(self.rythmInstrument, self.beat, self.regularity, self.reverb, None) )] - self.notesList.sort() + i = 0 + self.noteList= [] + self.csnd.loopClear() + for x in flatten( generator(self.rythmInstrument, self.beat, self.regularity, self.reverb) ): + n = Note(0, x.trackId, i, x) + self.noteList.append( (x.onset, n) ) + i = i + 1 + self.csnd.loopPlay(n) self.csnd.loopSetNumTicks( self.beat * Config.TICKS_PER_BEAT) - self.csnd.loopSet_onset_note( self.notesList) def handleGenerationSlider(self, adj): img = int(adj.value * 7)+1 @@ -422,7 +428,7 @@ class StandAlonePlayer( gtk.EventBox ): self.playStartupSound() def enableKeyboard( self ): - self.keyboardStandAlone = KeyboardStandAlone( self.csnd, self.rythmPlayer.recording, self.rythmPlayer.adjustDuration, self.rythmPlayer.getCurrentTick, self.rythmPlayer.getPlayState ) + self.keyboardStandAlone = KeyboardStandAlone( self.rythmPlayer.recording, self.rythmPlayer.adjustDuration, self.csnd.loopGetTick, self.rythmPlayer.getPlayState ) self.add_events(gtk.gdk.BUTTON_PRESS_MASK) def setInstrument( self , instrument ): @@ -430,7 +436,8 @@ class StandAlonePlayer( gtk.EventBox ): self.keyboardStandAlone.setInstrument(instrument) def playInstrumentNote(self , instrument, secs_per_tick = 0.025): - note = CSoundNote( onset = 0, + self.csnd.play( + CSoundNote( onset = 0, pitch = 36, amplitude = 1, pan = 0.5, @@ -439,8 +446,8 @@ class StandAlonePlayer( gtk.EventBox ): fullDuration = False, instrument = instrument, instrumentFlag = instrument, - reverbSend = 0) - note.playNow(secs_per_tick) + reverbSend = 0), + secs_per_tick) def handleKeyboard(self, widget, event): if event.hardware_keycode == 65: diff --git a/SynthLab/SynthLabWindow.py b/SynthLab/SynthLabWindow.py index 6248418..b0c03a6 100644 --- a/SynthLab/SynthLabWindow.py +++ b/SynthLab/SynthLabWindow.py @@ -11,7 +11,7 @@ import os import Config from Util.ThemeWidgets import * -from Util.CSoundClient import CSoundClient +from Util.CSoundClient import new_csound_client from SynthLab.SynthLabParametersWindow import SynthLabParametersWindow from SynthLab.SynthObjectsParameters import SynthObjectsParameters from SynthLab.SynthLabConstants import SynthLabConstants @@ -20,13 +20,13 @@ from Util.Trackpad import Trackpad Tooltips = Config.Tooltips class SynthLabWindow( gtk.Window ): - def __init__( self, client, table, closeCallback ): + def __init__( self, table, closeCallback ): gtk.Window.__init__( self, gtk.WINDOW_TOPLEVEL ) color = gtk.gdk.color_parse(Config.PANEL_BCK_COLOR) self.modify_bg(gtk.STATE_NORMAL, color) self.set_border_width(Config.MAIN_WINDOW_PADDING) self.set_keep_above(False) - self.csnd = client + self.csnd = new_csound_client() self.trackpad = Trackpad( self, self.csnd ) self.table = table self.closeCallback = closeCallback @@ -15,16 +15,6 @@ try : except ImportError: print "No Sugar for you" -def init_csound(): - #csnd = CSoundClient.CSoundClientSocket( Config.SERVER_ADDRESS, Config.SERVER_PORT, os.getpid() ) - #csnd = CSoundClient.CSoundClientPerf( '/usr/share/olpc-csound-server/univorc.csd' ) - #csnd = CSoundClient.CSoundClientPerf( Config.TAM_TAM_ROOT + '/Resources/univorc.csd' ) - csnd = CSoundClient.CSoundClientPlugin( Config.TAM_TAM_ROOT + '/Resources/univorc.csd' ) - csnd.connect(True) - csnd.setMasterVolume(100.0) - CSoundClient.CSoundClient = csnd #Dodgy move: TODO: remove this global variable. - return csnd - if not os.path.isdir(Config.PREF_DIR): os.mkdir(Config.PREF_DIR) os.system('chmod 0777 ' + Config.PREF_DIR + ' &') @@ -33,10 +23,8 @@ if not os.path.isdir(Config.PREF_DIR): os.system('chmod 0777 ' + Config.PREF_DIR + '/' + snd + ' &') if __name__ == "__main__": - csnd = init_csound() - def run_non_sugar_mode(): - tamtam = StandAlonePlayer(csnd) + tamtam = StandAlonePlayer() mainwin = gtk.Window(gtk.WINDOW_TOPLEVEL) color = gtk.gdk.color_parse('#FFFFFF') mainwin.modify_bg(gtk.STATE_NORMAL, color) @@ -49,11 +37,10 @@ if __name__ == "__main__": mainwin.add(tamtam) tamtam.show() mainwin.show() - csnd.load_instruments() gtk.main() def run_edit_mode(): - tamtam = MainWindow(csnd) + tamtam = MainWindow() mainwin = gtk.Window(gtk.WINDOW_TOPLEVEL) mainwin.set_title('TamTam Player') mainwin.set_geometry_hints( None, 1200, 900, 1200, 900, 1200, 900 ) @@ -67,7 +54,6 @@ if __name__ == "__main__": mainwin.add(tamtam) tamtam.show() mainwin.show() - csnd.load_instruments() gtk.main() if len(sys.argv) > 1 and sys.argv[1] == 'edit': @@ -81,8 +67,6 @@ if __name__ == "__main__": else: run_non_sugar_mode() - csnd.connect(False) - csnd.destroy() sys.exit(0) class TamTam(Activity): @@ -92,30 +76,29 @@ class TamTam(Activity): color = gtk.gdk.color_parse('#FFFFFF') self.modify_bg(gtk.STATE_NORMAL, color) - self.csnd = init_csound() - self.tamtam = StandAlonePlayer(self.csnd) + self.tamtam = StandAlonePlayer() self.connect('focus_in_event',self.handleFocusIn) self.connect('focus_out_event',self.handleFocusOut) self.connect('destroy', self.do_quit) self.add(self.tamtam) self.tamtam.show() - self.csnd.load_instruments() self.set_title('TamTam') self.set_resizable(False) self.connect( "key-press-event", self.tamtam.keyboardStandAlone.onKeyPress ) self.connect( "key-release-event", self.tamtam.keyboardStandAlone.onKeyRelease ) def handleFocusIn(self, event, data=None): - self.csnd.connect(True) - self.csnd.load_instruments() + csnd = new_csound_client() + csnd.connect(True) + csnd.load_instruments() def handleFocusOut(self, event, data=None): if self.tamtam.synthLabWindowOpen(): return - self.csnd.connect(False) + csnd = new_csound_client() + csnd.connect(False) def do_quit(self, arg2): os.system('rm ' + Config.PREF_DIR + '/synthTemp*') - self.csnd.destroy() del self.tamtam diff --git a/Util/CSoundClient.py b/Util/CSoundClient.py index a1242a3..4d3bfef 100644 --- a/Util/CSoundClient.py +++ b/Util/CSoundClient.py @@ -10,166 +10,21 @@ import array import Config from Generation.GenerationConstants import GenerationConstants +from Util.Clooper.sclient import * +from Util import NoteDB -#---------------------------------------------------------------------- -# A CSound client used to send messages to the CSound server -# CSoundClient is a singleton -#---------------------------------------------------------------------- -CSoundClient = None -class CSoundClientBase: - def setMasterVolume(self, volume): - self.sendText("csound.SetChannel('masterVolume', %f)\n" % volume) - - def micRecording( self, table ): - mess = Config.MIC_RECORDING_COMMAND % table - self.sendText( mess ) - - def load_mic_instrument( self, inst ): - fileName = Config.PREF_DIR + '/' + inst - instrumentId = Config.INSTRUMENT_TABLE_OFFSET + int(fileName[-1]) + 6 - mess = Config.LOAD_INSTRUMENT_COMMAND % ( instrumentId, fileName ) - self.sendText( mess ) - - def load_instruments( self ): - for instrumentSoundFile in Config.INSTRUMENTS.keys(): - if instrumentSoundFile[0:3] == 'mic' or instrumentSoundFile[0:3] == 'lab': - fileName = Config.PREF_DIR + '/' + instrumentSoundFile - else: - fileName = Config.SOUNDS_DIR + "/" + instrumentSoundFile - instrumentId = Config.INSTRUMENT_TABLE_OFFSET + Config.INSTRUMENTS[ instrumentSoundFile ].instrumentId - mess = Config.LOAD_INSTRUMENT_COMMAND % ( instrumentId, fileName ) - self.sendText( mess ) - - def startTime(self): - raise 'dont do this anymore' - self.sendText("perf.InputMessage('i 5999 0.0 60000000')") - # if any other message arrives to csound at the same time as this one, - # then the global variables will not be set up right in the orcestra - # - # NB: match this to the constant in the instrument 5777 of the csound orcestra - time.sleep(0.1) - - def sendText(self, txt): - raise 'noImpl' - - def connect(self, flag): - raise 'noImpl' - - def destroy(self): - pass - - - -class CSoundClientSocket( CSoundClientBase ): - def __init__( self, serverAddress, serverPort, clientId ): - self.clientId = clientId - self.serverInfo = ( serverAddress, serverPort ) - self.connected = False - - def sendText( self, text ): - #print "Sending to CSound server: %s" % text - try: - self.socket.send( text ) - except socket.error: - if Config.SERVER_REQUIRED : - print 'ERROR: no CSound server. Ignoring message: %s' % text - - def connect( self, init = True ): - if init : - n = Config.INIT_ATTEMPTS - self.socket = socket.socket() - self.connected = False - while n > 0 and not self.connected: - try: - self.socket.connect( self.serverInfo ) - self.connected = True - self.load_instruments() - except socket.error: - if Config.SERVER_REQUIRED : - print 'ERROR: no CSound server. Ignoring connection request.' - time.sleep(Config.INIT_DELAY) - n = n - 1 - else : #un-init - self.sendText( Config.UNLOAD_TABLES_COMMAND ) - del self.socket - -class CSoundClientPerf( CSoundClientBase ): +class _CSoundClientPlugin: def __init__(self, orc): - self.orc = orc + sc_initialize(orc) self.on = False - self.csound = csnd.Csound() - def connect( self, init = True ): - if init: - if self.on : return - self.on = True - self.perf = csnd.CsoundPerformanceThread(self.csound) - self.csound.Compile( self.orc ) - self.perf.Play() - self.load_instruments() - print 'CSoundClient = True' - else: - if not self.on : return - self.on = False - #self.csound.SetChannel('udprecv.0.on', 0) - #print Config.UNLOAD_TABLES_COMMAND - self.sendText( Config.UNLOAD_TABLES_COMMAND ) - #print 'PERF STOP' - self.perf.Stop() - #print 'SLEEP' - #time.sleep(1) - #print 'JOIN' - #time.sleep(1) - rval = self.perf.Join() - #print 'Join returned ', rval - #del self.perf - #time.sleep(1) - #print 'STOP' - #self.csound.Stop() - #print 'RESET' - self.csound.Reset() - print 'CSoundClient = False' - #careful how much cleaning up we do... don't cause a segault! - # better to leave a segfault for the automatic cleanning at the end of the prog - - #self.csound.Cleanup() - #print 'STOPPED' - #time.sleep(1) - #del self.csound - #print 'DELETED' - #time.sleep(1) - def setMasterVolume(self, volume): - self.csound.SetChannel('masterVolume',volume ) + self.masterVolume = 80.0 - def sendText(self, txt): - #print txt - perf = self.perf - csound = self.csound - if 'csound' in txt: - print txt - import sys - sys.exit(0) - exec txt - -class CSoundClientPipe( CSoundClientBase ): - def __init__(self, orc): - self.orc = orc - def connect( self, init = True ): - if init: - (self.child_out, self.child_in) = os.popen2('csound ' + self.orc) - else: - self.child_in.close() - self.child_out.close() + def __del__(self): + self.connect(False) + sc_destroy() - def sendText(self, txt): - str = txt[19:-3] - if len(str) == 0: return - #print 'tosend:[%s]' % (str,) - self.child_out.write(str) -from Util.Clooper.sclient import * -from Util import NoteDB -class CSoundClientPlugin( CSoundClientBase ): def setMasterVolume(self, volume): self.masterVolume = volume if self.on: @@ -191,11 +46,6 @@ class CSoundClientPlugin( CSoundClientBase ): instrumentId = Config.INSTRUMENT_TABLE_OFFSET + int(fileName[-1]) + 6 sc_inputMessage(Config.CSOUND_LOAD_INSTRUMENT % (instrumentId, fileName)) - def __init__(self, orc): - sc_initialize(orc) - self.on = False - self.masterVolume = 80.0 - def load_instruments( self ): for instrumentSoundFile in Config.INSTRUMENTS.keys(): if instrumentSoundFile[0:3] == 'mic' or instrumentSoundFile[0:3] == 'lab': @@ -308,14 +158,13 @@ class CSoundClientPlugin( CSoundClientBase ): print 'ERROR: loopUpdate(): unsupported parameter change' def loopPlay(self, dbnote): qid = (dbnote.page << 16) + dbnote.id - print qid sc_loop_addScoreEvent( qid, 1, 'i', self.csnote_to_array(dbnote.cs)) - def play(self, dbnote, secs_per_tick): - a = self.csnote_to_array(dbnote.cs) - a[1] = a[0] * secs_per_tick - a[8] = max(a[8]*a[1], 0.002) - a[9] = max(a[9]*a[1], 0.002) - cs_addScoreEvent( 'i', a) + def play(self, csnote, secs_per_tick): + a = self.csnote_to_array(csnote) + a[self.DURATION] = a[self.DURATION] * secs_per_tick + a[self.ATTACK] = max(a[self.ATTACK]*a[self.DURATION], 0.002) + a[self.DECAY] = max(a[self.DECAY]*a[self.DURATION], 0.002) + sc_scoreEvent( 'i', a) def csnote_to_array(self, csnote): return self.csnote_to_array1( @@ -335,6 +184,13 @@ class CSoundClientPlugin( CSoundClientBase ): csnote.overlap, csnote.instrumentFlag) + INSTR_TRACK=0 + ONSET=1 + DURATION=2 + PITCH=3 + AMPLITUDE=5 + ATTACK=8 + DECAY=9 def csnote_to_array1( self, onset, pitch, amplitude, @@ -402,3 +258,14 @@ class CSoundClientPlugin( CSoundClientBase ): Config.INSTRUMENTS[ instr ].crossDur ]) return a + +_Client = None + +def new_csound_client(): + global _Client + if _Client == None: + _Client = _CSoundClientPlugin( Config.TAM_TAM_ROOT + '/Resources/univorc.csd' ) + _Client.connect(True) + _Client.setMasterVolume(100.0) + _Client.load_instruments() + return _Client |