diff options
author | James <olpc@localhost.localdomain> | 2007-01-22 09:12:15 (GMT) |
---|---|---|
committer | James <olpc@localhost.localdomain> | 2007-01-22 09:12:15 (GMT) |
commit | 962b90d00c747532481560a44ca03a8205363232 (patch) | |
tree | fdaad30f332dc9d6c6ac616dd218942262529512 /Util/CSoundNote.py | |
parent | 2fcb4c0d3d2a42dd89a6aab92838dda675230de1 (diff) |
steady prog on new csound client
Diffstat (limited to 'Util/CSoundNote.py')
-rw-r--r-- | Util/CSoundNote.py | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/Util/CSoundNote.py b/Util/CSoundNote.py index 848d569..03c6b87 100644 --- a/Util/CSoundNote.py +++ b/Util/CSoundNote.py @@ -2,6 +2,102 @@ import Config from Util.CSoundClient import CSoundClient from Generation.GenerationConstants import GenerationConstants +from Util.Clooper.SClient import * +from sugar import env + +def CSound_loadInstruments( ): + home_path = env.get_profile_path() + Config.PREF_DIR + for instrumentSoundFile in Config.INSTRUMENTS.keys(): + if instrumentSoundFile[0:3] == 'mic' or instrumentSoundFile[0:3] == 'lab': + fileName = home_path + '/' + instrumentSoundFile + else: + fileName = Config.SOUNDS_DIR + "/" + instrumentSoundFile + instrumentId = Config.INSTRUMENT_TABLE_OFFSET + Config.INSTRUMENTS[ instrumentSoundFile ].instrumentId + sc_instrumentLoad(instrumentId, fileName) + +def CSound_playNote( loopMode, secs_per_tick, + onset, + pitch, + amplitude, + pan, + duration, + trackId, + fullDuration = False, + attack = 0.002, + decay = 0.098, + reverbSend = 0.1, + filterType = 0, + filterCutoff = 1000, + tied = False, + overlap = False, + instr = Config.FLUTE ): + + if not loopMode: duration = secs_per_tick * duration + + if instr[0:4] == 'drum': + if pitch in GenerationConstants.DRUMPITCH: + key = GenerationConstants.DRUMPITCH[ pitch ] + else: + key = pitch + + if instr == 'drum1kit': + instr = Config.DRUM1INSTRUMENTS[ key ] + if instr == 'drum2kit': + instr = Config.DRUM2INSTRUMENTS[ key ] + if instr == 'drum3kit': + instr = Config.DRUM3INSTRUMENTS[ key ] + pitch = 1 + else: + pitch = GenerationConstants.TRANSPOSE[ pitch - 24 ] + + # condition for tied notes + if Config.INSTRUMENTS[ instr ].csoundInstrumentId == 101 and tied and fullDuration: + duration= -1.0 + # condition for overlaped notes + if Config.INSTRUMENTS[ instr ].csoundInstrumentId == 102 and overlap: + duration += 1.0 + + # condition for tied notes + if Config.INSTRUMENTS[ instr].csoundInstrumentId == Config.INST_TIED and tied and fullDuration: + duration = -1 + # condition for overlaped notes + if Config.INSTRUMENTS[ instr ].csoundInstrumentId == Config.INST_PERC and overlap: + duration = duration + 1.0 + if loopMode : + sc_loop_addScoreEvent15( 'i', + Config.INSTRUMENTS[ instr ].csoundInstrumentId + 0.1,# trackId * 0.01, + onset, + duration, + pitch, + reverbSend, + amplitude, + pan, + Config.INSTRUMENT_TABLE_OFFSET + Config.INSTRUMENTS[instr].instrumentId, + max(attack*duration, 0.002), + max(decay *duration, 0.002), + filterType, + filterCutoff, + Config.INSTRUMENTS[ instr ].loopStart, + Config.INSTRUMENTS[ instr ].loopEnd, + Config.INSTRUMENTS[ instr ].crossDur ) + else: + sc_scoreEvent15( 'i', + Config.INSTRUMENTS[ instr ].csoundInstrumentId + 0.1,# trackId * 0.01, + onset * secs_per_tick, + duration, + pitch, + reverbSend, + amplitude, + pan, + Config.INSTRUMENT_TABLE_OFFSET + Config.INSTRUMENTS[instr].instrumentId, + max(attack*duration, 0.002), + max(decay *duration, 0.002), + filterType, + filterCutoff, + Config.INSTRUMENTS[ instr ].loopStart, + Config.INSTRUMENTS[ instr ].loopEnd, + Config.INSTRUMENTS[ instr ].crossDur ) + class CSoundNote : #----------------------------------- # initialization @@ -136,3 +232,39 @@ class CSoundNote : Config.INSTRUMENTS[ self.instrumentFlag ].loopStart, Config.INSTRUMENTS[ self.instrumentFlag ].loopEnd, Config.INSTRUMENTS[ self.instrumentFlag ].crossDur ) + + def playNow(self, secs_per_tick): + CSound_playNote( False, secs_per_tick, + self.onset, + self.pitch, + self.amplitude, + self.pan, + self.duration, + self.trackId, + self.fullDuration, + self.attack, + self.decay, + self.reverbSend, + self.filterType, + self.filterCutoff, + self.tied, + self.overlap, + self.instrumentFlag) + def playLoop(self): + CSound_playNote( True, 1.0, + self.onset, + self.pitch, + self.amplitude, + self.pan, + self.duration, + self.trackId, + self.fullDuration, + self.attack, + self.decay, + self.reverbSend, + self.filterType, + self.filterCutoff, + self.tied, + self.overlap, + self.instrumentFlag) + |