Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/miniTamTam/KeyboardStandAlone.py
diff options
context:
space:
mode:
Diffstat (limited to 'miniTamTam/KeyboardStandAlone.py')
-rw-r--r--miniTamTam/KeyboardStandAlone.py89
1 files changed, 46 insertions, 43 deletions
diff --git a/miniTamTam/KeyboardStandAlone.py b/miniTamTam/KeyboardStandAlone.py
index b783070..fcbca15 100644
--- a/miniTamTam/KeyboardStandAlone.py
+++ b/miniTamTam/KeyboardStandAlone.py
@@ -7,9 +7,12 @@ from Generation.GenerationConstants import GenerationConstants
from Util.NoteDB import Note
from Util.CSoundNote import CSoundNote
from Util.CSoundClient import new_csound_client
+from Util import Instrument
KEY_MAP_PIANO = Config.KEY_MAP_PIANO
+#log = file('/home/olpc/log.tamtam','w')
+
class KeyboardStandAlone:
def __init__( self, recordingFunction, adjustDurationFunction, getCurrentTick, getPlayState, loop ):
self.csnd = new_csound_client()
@@ -58,53 +61,53 @@ class KeyboardStandAlone:
self.trackCount += 1
# If the pressed key is in the keymap
if KEY_MAP_PIANO.has_key(key):
- # CsoundNote parameters
+ def playkey(pitch,duration,instrument):
+ # Create and play the note
+ self.key_dict[key] = CSoundNote(onset = 0,
+ pitch = pitch,
+ amplitude = volume,
+ pan = 0.5,
+ duration = duration,
+ trackId = track,
+ instrumentId = instrument.instrumentId,
+ reverbSend = self.reverb,
+ tied = True,
+ mode = 'mini')
+ self.csnd.play(self.key_dict[key], 0.3)
+ if self.getPlayState():
+ recOnset = self.csnd.loopGetTick()
+ self.onset_dict[key] = recOnset
+ self.recording( CSoundNote(
+ onset = recOnset,
+ pitch = pitch,
+ amplitude = volume,
+ pan = 0.5,
+ duration = 100,
+ trackId = 0,
+ decay = .1,
+ instrumentId = instrument.instrumentId,
+ reverbSend = self.reverb,
+ tied = False,
+ mode = 'mini'))
+
+ instrumentName = self.instrument
+ #print >>log, 'instrumentName:', instrumentName
pitch = KEY_MAP_PIANO[key]
- duration = -1
- instrument = self.instrument
-
- if event.state == gtk.gdk.MOD1_MASK:
- pitch = pitch+5
- if instrument[ 0: 4 ] == 'drum':
- if GenerationConstants.DRUMPITCH.has_key( pitch ):
- pitch = GenerationConstants.DRUMPITCH[ pitch ]
+ if instrumentName in Instrument.KIT:
+ #print >>log, 'kit_element: ', Config.KIT_ELEMENT[pitch]
+ playkey(36,100, Instrument.KIT[instrumentName][ Config.KIT_ELEMENT[pitch] ] )
- if Config.INSTRUMENTS[instrument].kit != None:
- instrument = Config.INSTRUMENTS[instrument].kit[pitch].name
- pitch = 36
- duration = 100
+ else:
+ if event.state == gtk.gdk.MOD1_MASK:
+ pitch += 5
- if Config.INSTRUMENTS[instrument].csoundInstrumentId == Config.INST_PERC: #Percussions resonance
- duration = 60
+ instrument = Instrument.INST[ instrumentName ]
+ if instrument.csoundInstrumentName == 'inst_perc': #Percussions resonance
+ playkey( pitch, 60, instrument)
+ else:
+ playkey( pitch, -1, instrument)
- # Create and play the note
- self.key_dict[key] = CSoundNote(onset = 0,
- pitch = pitch,
- amplitude = volume,
- pan = 0.5,
- duration = duration,
- trackId = track,
- instrumentId = Config.INSTRUMENTS[instrument].instrumentId,
- reverbSend = self.reverb,
- tied = True,
- mode = 'mini')
- self.csnd.play(self.key_dict[key], 0.3)
- if self.getPlayState():
- recOnset = self.csnd.loopGetTick()
- self.onset_dict[key] = recOnset
- self.recording( CSoundNote(
- onset = recOnset,
- pitch = pitch,
- amplitude = volume,
- pan = 0.5,
- duration = 100,
- trackId = 0,
- decay = .1,
- instrumentId = Config.INSTRUMENTS[instrument].instrumentId,
- reverbSend = self.reverb,
- tied = False,
- mode = 'mini'))
def onKeyRelease(self,widget,event):
key = event.hardware_keycode
@@ -120,7 +123,7 @@ class KeyboardStandAlone:
if KEY_MAP_PIANO.has_key(key):
csnote = self.key_dict[key]
- if Config.INSTRUMENTSID[ csnote.instrumentId ].csoundInstrumentId == Config.INST_TIED:
+ if Instrument.INST_byId[ csnote.instrumentId ].csoundInstrumentName == 'inst_tied':
csnote.duration = .5
csnote.decay = 0.7
#csnote.amplitude = 1