diff options
author | James <james@mackie.fourth> | 2007-03-20 02:35:16 (GMT) |
---|---|---|
committer | James <james@mackie.fourth> | 2007-03-20 02:35:16 (GMT) |
commit | 84d6431b1d98c16d93528723c9f14daf24c47ca9 (patch) | |
tree | 18c6b42b1c133645646929a08be66b6aeea18c8c /mini.py | |
parent | fb75c8c382ebd2260a2600c6bfdfc0efefe6449d (diff) |
misc fixes, verbose client logging
Diffstat (limited to 'mini.py')
-rw-r--r-- | mini.py | 231 |
1 files changed, 112 insertions, 119 deletions
@@ -1,123 +1,116 @@ -from Framework.CSound.CSoundClient import CSoundClient -from Framework.NoteLooper import NoteLooper as NL - -import time -import math - -lookahead = 0.2 -nl = NL( lookahead, 20.0, ['drum1kit'], [1.0], [1.0] ) - -nl.notes = [ - #(0, {'fullDuration': False, 'pageID': 0, 'decay': 0.098000000000000004, 'trackID': 0, 'instrumentFlag': 'drum1kick', 'filterType': 0, 'tied': False, 'onset': 0, 'filterCutoff': 1000, 'attack': 0.002, 'reverbSend': 0.10000000000000001, 'overlap': False, 'amplitude': 0.92029484351363555, 'pitch': 24, 'duration': 1, 'noteID': 36, 'pan': 0.5}, ''), - #( 0, {'fullDuration': False, 'pageID': 0, 'decay': 0.098000000000000004, 'trackID': 0, 'instrumentFlag': 'flute', 'filterType': 0, 'tied': False, 'onset': 0, 'filterCutoff': 1000, 'attack': 0.002, 'reverbSend': 0.10000000000000001, 'overlap': False, 'amplitude': 0.92525578482634807, 'pitch': 29, 'duration': 4, 'noteID': 1, 'pan': 0.5}, ''), - #(0, {'fullDuration': False, 'pageID': 0, 'decay': 0.098000000000000004, 'trackID': 0, 'instrumentFlag': 'koto', 'filterType': 0, 'tied': False, 'onset': 0, 'filterCutoff': 1000, 'attack': 0.002, 'reverbSend': 0.10000000000000001, 'overlap': False, 'amplitude': 0.939434987358156, 'pitch': 38, 'duration': 5, 'noteID': 8, 'pan': 0.5}, ''), - (0, {'fullDuration': False, 'pageID': 0, 'decay': 0.098000000000000004, 'trackID': 0, 'instrumentFlag': 'gam', 'filterType': 0, 'tied': False, 'onset': 0, 'filterCutoff': 1000, 'attack': 0.002, 'reverbSend': 0.10000000000000001, 'overlap': False, 'amplitude': 0.94494314329224738, 'pitch': 24, 'duration': 5, 'noteID': 22, 'pan': 0.5}, ''), - #(0, {'fullDuration': False, 'pageID': 0, 'decay': 0.098000000000000004, 'trackID': 0, 'instrumentFlag': 'guit', 'filterType': 0, 'tied': False, 'onset': 0, 'filterCutoff': 1000, 'attack': 0.002, 'reverbSend': 0.10000000000000001, 'overlap': False, 'amplitude': 0.94691792606223446, 'pitch': 35, 'duration': 5, 'noteID': 29, 'pan': 0.5}, ''), - #(6, {'fullDuration': False, 'pageID': 0, 'decay': 0.098000000000000004, 'trackID': 0, 'instrumentFlag': 'gam', 'filterType': 0, 'tied': False, 'onset': 6, 'filterCutoff': 1000, 'attack': 0.002, 'reverbSend': 0.10000000000000001, 'overlap': False, 'amplitude': 0.65465607337722664, 'pitch': 26, 'duration': 7, 'noteID': 23, 'pan': 0.5}, ''), - #(6, {'fullDuration': False, 'pageID': 0, 'decay': 0.098000000000000004, 'trackID': 0, 'instrumentFlag': 'gam', 'filterType': 0, 'tied': False, 'onset': 6, 'filterCutoff': 1000, 'attack': 0.002, 'reverbSend': 0.10000000000000001, 'overlap': False, 'amplitude': 0.66382312969855872, 'pitch': 28, 'duration': 5, 'noteID': 16, 'pan': 0.5}, ''), - #(6, {'fullDuration': False, 'pageID': 0, 'decay': 0.098000000000000004, 'trackID': 0, 'instrumentFlag': 'koto', 'filterType': 0, 'tied': False, 'onset': 6, 'filterCutoff': 1000, 'attack': 0.002, 'reverbSend': 0.10000000000000001, 'overlap': False, 'amplitude': 0.69112283960585841, 'pitch': 33, 'duration': 5, 'noteID': 9, 'pan': 0.5}, ''), - #(6, {'fullDuration': False, 'pageID': 0, 'decay': 0.098000000000000004, 'trackID': 0, 'instrumentFlag': 'drum1hatshoulder', 'filterType': 0, 'tied': False, 'onset': 6, 'filterCutoff': 1000, 'attack': 0.002, 'reverbSend': 0.10000000000000001, 'overlap': False, 'amplitude': 0.70739520974639736, 'pitch': 46, 'duration': 1, 'noteID': 46, 'pan': 0.5}, ''), - #(6, {'fullDuration': False, 'pageID': 0, 'decay': 0.098000000000000004, 'trackID': 0, 'instrumentFlag': 'flute', 'filterType': 0, 'tied': False, 'onset': 6, 'filterCutoff': 1000, 'attack': 0.002, 'reverbSend': 0.10000000000000001, 'overlap': False, 'amplitude': 0.72961742679087493, 'pitch': 31, 'duration': 5, 'noteID': 2, 'pan': 0.5}, '') - (0, {'fullDuration': True, 'pageID': 0, 'decay': 0.098000000000000004, 'trackID': 0, 'instrumentFlag': 'gam', 'filterType': 0, 'tied': False, 'onset': 0, 'filterCutoff': 1000, 'attack': 0.002, 'reverbSend': 0.10000000000000001, 'overlap': False, 'amplitude': 0.98273554224748583, 'pitch': 33, 'duration': 6, 'noteID': 15, 'pan': 0.5}, '') - ] - - -cmdEvent = [ - "perf.InputMessage('i 5777 0.0 0.001 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5019 0.002 0.004 0 1000.000000')", - "perf.InputMessage('i 5777 0.0 0.001 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5020 0.002 0.004 0 1000.000000')", - "perf.InputMessage('i 5777 0.0 0.001 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5021 0.002 0.004 0 1000.000000')", - "perf.InputMessage('i 5777 0.0 0.001 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5028 0.002 0.004 0 1000.000000')", - "perf.InputMessage('i 5777 0.0 0.001 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5017 0.002 0.004 0 1000.000000')", - "perf.InputMessage('i 5777 0.0 0.001 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5011 0.002 0.004 0 1000.000000')", - "perf.InputMessage('i 5777 0.0 0.001 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5012 0.002 0.004 0 1000.000000')", - "perf.InputMessage('i 5777 0.0 0.001 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5013 0.002 0.004 0 1000.000000')", - "perf.InputMessage('i 5777 0.0 0.001 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5012 0.002 0.004 0 1000.000000')" - ] -cmdStraight = [ - "perf.InputMessage('i 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5019 0.002 0.004 0 1000.000000')", - "perf.InputMessage('i 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5020 0.002 0.004 0 1000.000000')", - "perf.InputMessage('i 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5021 0.002 0.004 0 1000.000000')", - "perf.InputMessage('i 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5028 0.002 0.004 0 1000.000000')", - "perf.InputMessage('i 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5017 0.002 0.004 0 1000.000000')", - "perf.InputMessage('i 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5011 0.002 0.004 0 1000.000000')", - "perf.InputMessage('i 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5012 0.002 0.004 0 1000.000000')", - "perf.InputMessage('i 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5013 0.002 0.004 0 1000.000000')", - "perf.InputMessage('i 5003.5 %f 0.050000 1.000000 0.100000 0.773 0.500000 5012 0.002 0.004 0 1000.000000')" - ] - -CSoundClient.initialize() -CSoundClient.setMasterVolume(100.0) - - - -i = 0 -t1 = time.time() -m = v = vv = 0.0 - -loopsleep = 0.05 -loopdelay = 0.1 - - -time0 = time.time() -nl.setDuration(12) -nl.setTick(0) -CSoundClient.startTime() - -while True : - - t0 = t1 - i = i + 1 - now = time.time() - if True: - next = nl.next() - for n in next: - CSoundClient.sendText(n) - - elif True: - j = i % 4 - if j == 0: - CSoundClient.sendText( cmdEvent[1] % ( (now - time0) + loopdelay, )) - CSoundClient.sendText( cmdEvent[3] % ( (now - time0) + loopdelay, ) ) - pass - elif j == 1: - CSoundClient.sendText( cmdEvent[4] % ( (now - time0) + loopdelay, ) ) - CSoundClient.sendText( cmdEvent[5] % ( (now - time0) + loopdelay, ) ) - pass - elif j == 2: - CSoundClient.sendText( cmdEvent[2] % ( (now - time0) + loopdelay, ) ) - CSoundClient.sendText( cmdEvent[5] % ( (now - time0) + loopdelay, ) ) - pass - else: - CSoundClient.sendText( cmdEvent[1] % ( (now - time0) + loopdelay, )) - CSoundClient.sendText( cmdEvent[4] % ( (now - time0) + loopdelay, ) ) - elif True: - j = i % 4 - if j == 0: - CSoundClient.sendText( cmdStraight[1] % (loopdelay, )) - CSoundClient.sendText( cmdStraight[3] % (loopdelay, ) ) - pass - elif j == 1: - CSoundClient.sendText( cmdStraight[4] % (loopdelay, ) ) - CSoundClient.sendText( cmdStraight[5] % (loopdelay, ) ) - pass - elif j == 2: - CSoundClient.sendText( cmdStraight[2] % (loopdelay, ) ) - CSoundClient.sendText( cmdStraight[5] % (loopdelay, ) ) - pass - else: - CSoundClient.sendText( cmdStraight[1] % (loopdelay, )) - CSoundClient.sendText( cmdStraight[4] % (loopdelay, ) ) - time.sleep(loopsleep) - t1 = time.time() +from Util.CSoundClient import new_csound_client +from Util.NoteDB import PARAMETER, NoteDB +from Util.ControlStream import * + + +class MiniPlayer: + def __init__(self, ndb): + self.csnd = new_csound_client() + self.csnd.connect(True) + self.csnd.loopSetNumTicks(50) + self.csnd.loopStart() + self.csnd.setMasterVolume(1.0) + self.csnd.setTrackVolume(1.0, 1) - r = 1.0 / i - d = t1 - t0 - m = r * d + (1.0 - r) * m - v = r * d * d + (1.0 - r) * v - vv = r * d * d * d + (1.0 - r) * v + self.noteDB = ndb + ndb.addListener( self, page=True, note=True ) - #print m, math.sqrt(v - m * m ), math.pow( vv - m*m*m, 0.333333) - break -CSoundClient.initialize(False) + def recompose( self, algo, params, genOrVar): + + newtracks = set(range(Config.NUMBER_OF_TRACKS)) + newpages = self.tuneInterface.getSelectedIds() + + if genOrVar == 0: + dict = {} + for t in newtracks: + dict[t] = {} + for p in newpages: + dict[t][p] = self.noteDB.getCSNotesByTrack( p, t ) + else: + dict = {} + for t in newtracks: + dict[t] = {} + dict[t][1] = self.noteDB.getCSNotesByTrack( 1, t ) + + beatsOfPages = {} + for pageId in newpages: + beatsOfPages[pageId] = self.noteDB.pages[pageId].beats + + algo( + params, + self._data['track_volume'][:], + [ i.name for i in self.trackInstrument ], + self._data['tempo'], + beatsOfPages, + newtracks, + newpages, + dict) + + # filter & fix input ...WTF!? + for track in dict: + for page in dict[track]: + for note in dict[track][page]: + intdur = int(note.duration) + note.duration = intdur + note.pageId = page + note.trackId = track + + # prepare the new notes + newnotes = [] + for tid in dict: + for pid in dict[tid]: + newnotes += dict[tid][pid] + + # delete the notes and add the new + self.noteDB.deleteNotesByTrack( newpages, newtracks ) + + stream = [] + for page in newpages: + for track in newtracks: + stream += [ page, track, len(dict[track][page]) ] + stream += dict[track][page] + stream += [-1] + self.noteDB.addNotes( stream ) + def notifyPageAdd( self, id, at ): + return + + def notifyPageDelete( self, which, safe ): + pass + + def notifyPageDuplicate( self, new, at ): + return + + def notifyPageMove( self, which, low, high ): + return + + def notifyNoteAdd( self, page, track, id ): + print 'INFO: adding note to loop', page, track, id + n = self.noteDB.getNote(page, track, id) + self.csnd.loopPlay(n,0) + onset = n.cs.onset + 0 #self.page_onset[n.page] + self.csnd.loopUpdate(n, PARAMETER.ONSET, onset, 1) #set onset + activate + + def notifyNoteDelete( self, page, track, id ): + print 'INFO: deleting note from loop', page, track, id + self.csnd.loopDelete1(page,id) + def notifyNoteUpdate( self, page, track, id, parameter, value ): + print 'INFO: updating note ', page, id, parameter, value + note = self.noteDB.getNote(page, track, id) + self.csnd.loopUpdate(note, parameter, value, -1) + +if __name__ == '__main__': + ndb = NoteDB() + mplayer = MiniPlayer(ndb) + + ttt = TamTamTable(ndb) + table = ttt.parseTable() + while True: + l = sys.stdin.readline() + if l == '\n': break + cmdlist = l.split() + if cmdlist[0] not in table: + print 'ERROR: command %s not defined by parse table' % cmdlist[0] + else: + table[cmdlist[0]](cmdlist[1:]) |