From 3e9a586f404b70cda362cf888653de9c940fd849 Mon Sep 17 00:00:00 2001 From: Oli Date: Fri, 19 Oct 2007 08:08:02 +0000 Subject: switch to instrumentDB --- diff --git a/TamTamEdit.activity/Edit/MainWindow.py b/TamTamEdit.activity/Edit/MainWindow.py index 64892aa..772257e 100644 --- a/TamTamEdit.activity/Edit/MainWindow.py +++ b/TamTamEdit.activity/Edit/MainWindow.py @@ -4,6 +4,8 @@ import gtk import gobject +import common.Util.Instruments +import common.Util.InstrumentDB as InstrumentDB from common.Util.ThemeWidgets import * from common.Util.Profiler import TP from common.Util import NoteDB @@ -45,6 +47,7 @@ class MainWindow( gtk.EventBox ): def __init__( self, activity ): gtk.EventBox.__init__(self) + self.instrumentDB = InstrumentDB.getRef() self.csnd = new_csound_client() self.tooltips = gtk.Tooltips() self.activity = activity @@ -56,7 +59,7 @@ class MainWindow( gtk.EventBox ): # META ALGO: [section, variation or not, nPages] A B A C # TODO: Different parameters sets for each tracks - self.tuneForm = [[0, False, 4], [1, False, 4], [0, True, 4], [2, False, 4]] + self.tuneForm = [[0, False, 4], [1, False, 4], [0, True, 2], [2, False, 2]] def init_data( ): TP.ProfileBegin("init_data") @@ -68,11 +71,11 @@ class MainWindow( gtk.EventBox ): #[ instrument index, ... ] self.trackInstrumentDefault = [ - Config.INSTRUMENTS["kalimba"], - Config.INSTRUMENTS["kalimba"], - Config.INSTRUMENTS["kalimba"], - Config.INSTRUMENTS["kalimba"], - Config.INSTRUMENTS["drum2kit"] ] + self.instrumentDB.instNamed["kalimba"], + self.instrumentDB.instNamed["kalimba"], + self.instrumentDB.instNamed["kalimba"], + self.instrumentDB.instNamed["kalimba"], + self.instrumentDB.instNamed["drum2kit"] ] self.trackInstrument = self.trackInstrumentDefault[:] if len(self.trackInstrument) != Config.NUMBER_OF_TRACKS: raise 'error' self.drumIndex = Config.NUMBER_OF_TRACKS - 1 @@ -112,7 +115,7 @@ class MainWindow( gtk.EventBox ): self.GUI["2instrumentPalette"] = instrumentPalette(_('Track 1 Volume'), self) def draw_inst_icons(): - instrumentNames = [ k for k in Config.INSTRUMENTS.keys() if (k[0:4] != 'drum' and k[0:4] != 'guid') or Config.INSTRUMENTS[k].kit ] + instrumentNames = [ k for k in self.instrumentDB.instNamed.keys() if (k[0:4] != 'drum' and k[0:4] != 'guid') or self.instrumentDB.instNamed[k].kit ] self.GUI["2instrumentIcons"] = {} for instrument in instrumentNames: try: @@ -461,20 +464,20 @@ class MainWindow( gtk.EventBox ): keyboardPickup = [] fxPickup = [] drumsPickup = ["drum1kit", "drum2kit", "drum3kit", "drum4kit", "drum5kit"] - for name in Config.INSTRUMENTS.keys(): - if Config.INSTRUMENTS[name].category == 'strings' and Config.INSTRUMENTS[name].name != 'violin': + for name in self.instrumentDB.instNamed.keys(): + if self.instrumentDB.instNamed[name].category == 'strings' and self.instrumentDB.instNamed[name].name != 'violin': stringsPickup.append(name) - elif Config.INSTRUMENTS[name].category == 'winds' and Config.INSTRUMENTS[name].name != 'didjeridu': + elif self.instrumentDB.instNamed[name].category == 'winds' and self.instrumentDB.instNamed[name].name != 'didjeridu': windsPickup.append(name) - elif Config.INSTRUMENTS[name].category == 'keyboard' or Config.INSTRUMENTS[name].category == 'percussions' and not name.startswith('drum'): - if Config.INSTRUMENTS[name].name != 'zap' and Config.INSTRUMENTS[name].name != 'cling': + elif self.instrumentDB.instNamed[name].category == 'keyboard' or self.instrumentDB.instNamed[name].category == 'percussions' and not name.startswith('drum'): + if self.instrumentDB.instNamed[name].name != 'zap' and self.instrumentDB.instNamed[name].name != 'cling': keyboardPickup.append(name) return [ - Config.INSTRUMENTS[random.choice(stringsPickup)], - Config.INSTRUMENTS[random.choice(stringsPickup)], - Config.INSTRUMENTS[random.choice(windsPickup)], - Config.INSTRUMENTS[random.choice(keyboardPickup)], - Config.INSTRUMENTS[random.choice(drumsPickup)] ] + self.instrumentDB.instNamed[random.choice(stringsPickup)], + self.instrumentDB.instNamed[random.choice(stringsPickup)], + self.instrumentDB.instNamed[random.choice(windsPickup)], + self.instrumentDB.instNamed[random.choice(keyboardPickup)], + self.instrumentDB.instNamed[random.choice(drumsPickup)] ] def chooseGenParams(self): choose = [random.randint(0,16) for x in range(4)] @@ -856,7 +859,7 @@ class MainWindow( gtk.EventBox ): self.GUI["9instrumentPopup"].hide() def donePickInstrument( self, instrumentName ): - self.handleInstrumentChanged( (self.last_clicked_instTrackID, Config.INSTRUMENTS[instrumentName]), self.last_clicked_instPrimary ) + self.handleInstrumentChanged( (self.last_clicked_instTrackID, self.instrumentDB.instNamed[instrumentName]), self.last_clicked_instPrimary ) btn = self.GUI["2instrument%dButton" % (self.last_clicked_instTrackID+1)] if self.last_clicked_instPrimary: btn.setPrimary( self.GUI["2instrumentIcons"][instrumentName] ) @@ -873,7 +876,7 @@ class MainWindow( gtk.EventBox ): self.GUI["2drumButton"].set_active( False ) def donePickDrum( self, drumName ): - self.handleInstrumentChanged( ( self.drumIndex, Config.INSTRUMENTS[drumName] ) ) + self.handleInstrumentChanged( ( self.drumIndex, self.instrumentDB.instNamed[drumName] ) ) self.GUI["2drumButton"].setImage( "main", self.GUI["2instrumentIcons"][drumName] ) self.GUI["2drumButton"].setImage( "alt", self.GUI["2instrumentIcons"][drumName] ) self.GUI["2drumButton"].set_active( False ) @@ -886,7 +889,7 @@ class MainWindow( gtk.EventBox ): pan = 0.5, duration = 20, trackId = 1, - instrumentId = Config.INSTRUMENTS[instrumentName].instrumentId, + instrumentId = self.instrumentDB.instNamed[instrumentName].instrumentId, reverbSend = 0), secs_per_tick) @@ -1220,7 +1223,7 @@ class MainWindow( gtk.EventBox ): page = self.noteDB.getPage(pageId) for i in range(Config.NUMBER_OF_TRACKS): if self.trackInstrument[i].instrumentId != page.instruments[i]: - self.trackInstrument[i] = Config.INSTRUMENTSID[page.instruments[i]] + self.trackInstrument[i] = self.instrumentDB.instId[page.instruments[i]] if i == Config.NUMBER_OF_TRACKS-1: btn = self.GUI["2drumButton"] btn.setImage( "main", self.GUI["2instrumentIcons"][self.trackInstrument[i].name] ) @@ -1481,7 +1484,7 @@ class MainWindow( gtk.EventBox ): if self.activity.activity_toolbar.title.is_focus(): return - + # backspace and del keys if keyval == gtk.keysyms.Delete or keyval == gtk.keysyms.BackSpace: if self.context == CONTEXT.PAGE: self.pageDelete() @@ -1516,7 +1519,7 @@ class MainWindow( gtk.EventBox ): def onKeyPress(self,widget,event): - + self.handleKeyboardShortcuts(event) Config.ModKeys.keyPress( event.hardware_keycode ) key = event.hardware_keycode @@ -1549,8 +1552,8 @@ class MainWindow( gtk.EventBox ): if tid == Config.NUMBER_OF_TRACKS-1: if GenerationConstants.DRUMPITCH.has_key( pitch ): pitch = GenerationConstants.DRUMPITCH[pitch] - if Config.INSTRUMENTS[instrument].kit != None: - instrument = Config.INSTRUMENTS[instrument].kit[pitch].name + if self.instrumentDB.instNamed[instrument].kit != None: + instrument = self.instrumentDB.instNamed[instrument].kit[pitch].name duration = 100 # Create and play the note @@ -1560,7 +1563,7 @@ class MainWindow( gtk.EventBox ): pan = 0.5, duration = duration, trackId = fakeTrack, - instrumentId = Config.INSTRUMENTS[instrument].instrumentId, + instrumentId = self.instrumentDB.instNamed[instrument].instrumentId, tied = False, mode = 'edit') self.csnd.play(self.kb_keydict[key], 0.3) @@ -1633,7 +1636,7 @@ class MainWindow( gtk.EventBox ): pan = 0.5, duration = duration, trackId = index, - instrumentId = Config.INSTRUMENTS[instrument].instrumentId, + instrumentId = self.instrumentDB.instNamed[instrument].instrumentId, tied = False, mode = 'edit') @@ -1647,7 +1650,7 @@ class MainWindow( gtk.EventBox ): self.durUpdate = gobject.timeout_add( 25, self.durationUpdate ) def onKeyRelease(self,widget,event): - + Config.ModKeys.keyRelease( event.hardware_keycode ) key = event.hardware_keycode @@ -1663,7 +1666,7 @@ class MainWindow( gtk.EventBox ): gobject.source_remove( self.durUpdate ) self.durUpdate = False - if Config.INSTRUMENTSID[ self.kb_keydict[key].instrumentId ].csoundInstrumentId == Config.INST_TIED: + if self.instrumentDB.instId[ self.kb_keydict[key].instrumentId ].csoundInstrumentId == Config.INST_TIED: self.kb_keydict[key].duration = 0.5 self.kb_keydict[key].amplitude = 0 self.kb_keydict[key].decay = 0.5 @@ -1743,7 +1746,7 @@ class MainWindow( gtk.EventBox ): if stop: key = self.csId[4] - if Config.INSTRUMENTSID[ self.kb_keydict[key].instrumentId ].csoundInstrumentId == Config.INST_TIED: + if self.instrumentDB.instId[ self.kb_keydict[key].instrumentId ].csoundInstrumentId == Config.INST_TIED: self.kb_keydict[key].duration = 0.5 self.kb_keydict[key].amplitude = 0 self.kb_keydict[key].decay = 0.5 @@ -2080,6 +2083,7 @@ class instrumentPalette( Popup ): def __init__(self, label, edit): Popup.__init__(self, label, edit) + self.instrumentDB = InstrumentDB.getRef() self.edit = edit self.skip = False @@ -2098,7 +2102,7 @@ class instrumentPalette( Popup ): self.muteButton.connect("toggled",self.handlemuteButton) self.muteButton.set_active(True) self.tooltips.set_tip(self.muteButton, _('Mute track')) - + self.soloButtonLabel = gtk.Label(_('S')) self.soloButton = gtk.CheckButton() self.soloButton.connect("toggled",self.handlesoloButton) @@ -2111,10 +2115,10 @@ class instrumentPalette( Popup ): self.volumeSlider.set_size_request(250, -1) self.volumeSlider.set_inverted(False) self.volumeSlider.set_draw_value(False) - + self.categories = [cat.capitalize() for cat in Config.CATEGORIES] self.instruments = self.getInstruments() - + self.categoryBox = BigComboBox() for category in self.categories: image = Config.IMAGE_ROOT + category.lower() + '.png' @@ -2126,7 +2130,7 @@ class instrumentPalette( Popup ): self.instrumentBox1 = BigComboBox() self.loadInstrumentMenu(self.getInstruments()) self.instrumentBox1.connect('changed', self.handleInstrumentChange) - + self.volumeBox.pack_start(self.muteButtonLabel, padding = 5) self.volumeBox.pack_start(self.muteButton, padding = 5) #self.volumeBox.pack_start(self.soloButtonLabel, padding = 5) @@ -2139,17 +2143,17 @@ class instrumentPalette( Popup ): self.mainBox.show_all() self.set_content(self.mainBox) - + def handleTrackVolume(self, widget): if not self.skipVolAdj: if self.lastClickedTrack != None: self.edit.handleTrackVolume(widget = widget, track = self.lastClickedTrack) - + def handlemuteButton(self, widget): if not self.skipVolAdj: if self.lastClickedTrack != None: self.edit.handlemuteButton(widget, self.lastClickedTrack) - + def handlesoloButton(self, widget, event = None): pass @@ -2169,15 +2173,15 @@ class instrumentPalette( Popup ): if not self.skip: self.instrumentBox1.popup() #self.skip = False - + def setCategory(self, category): self.categoryBox.set_active(self.categories.index(category.capitalize())) - + def setInstrument(self, instrument): self.skip = True self.instrumentBox1.set_active(self.instruments.index(instrument)) self.skip = False - + def loadInstrumentMenu(self, instruments): self.instrumentBox1.remove_all() for instrument in instruments: @@ -2188,10 +2192,10 @@ class instrumentPalette( Popup ): def getInstruments(self, category = 'all'): if category == 'all': - return sorted([instrument for instrument in Config.INSTRUMENTS.keys() if not instrument.startswith('drum') and not instrument.startswith('guid')]) + return sorted([instrument for instrument in self.instrumentDB.instNamed.keys() if not instrument.startswith('drum') and not instrument.startswith('guid')]) else: - return sorted([instrument for instrument in Config.INSTRUMENTS.keys() if not instrument.startswith('drum') and not instrument.startswith('guid') and Config.INSTRUMENTS[instrument].category == category]) - + return sorted([instrument for instrument in self.instrumentDB.instNamed.keys() if not instrument.startswith('drum') and not instrument.startswith('guid') and self.instrumentDB.instNamed[instrument].category == category]) + def setBlock( self, widget = None, event = None, block = None ): if self.is_up(): self.popdown(True) @@ -2203,15 +2207,16 @@ class instrumentPalette( Popup ): self.muteButton.set_active(True) else: self.muteButton.set_active(False) - self.skipVolAdj = False + self.skipVolAdj = False self.lastClickedTrack = block self.popup( True ) - + class drumPalette( Popup ): ICON_SIZE = (70,70) def __init__(self, label, edit, trackID): Popup.__init__(self, label, edit) + self.instrumentDB = InstrumentDB.getRef() self.trackID = trackID self.edit = edit @@ -2239,13 +2244,13 @@ class drumPalette( Popup ): self.volumeSlider.set_size_request(250, -1) self.volumeSlider.set_inverted(False) self.volumeSlider.set_draw_value(False) - + self.drums = self.getDrums() self.drumBox = BigComboBox() self.loadDrumMenu(self.getDrums()) self.drumBox.connect('changed', self.handleInstrumentChange) - + self.volumeBox.pack_start(self.muteButton, padding = 5) self.volumeBox.pack_start(self.volumeSlider, padding = 5) self.mainBox.pack_start(self.volumeBox, padding = 5) @@ -2261,13 +2266,13 @@ class drumPalette( Popup ): self.edit.playInstrumentNote(drum) self.edit.donePickDrum(drum) self.popdown(True) - - + + def setDrum(self, Drum): self.skip = True self.drumBox.set_active(self.drums.index(Drum)) self.skip = False - + def loadDrumMenu(self, instruments): self.drumBox.remove_all() for instrument in instruments: @@ -2277,12 +2282,10 @@ class drumPalette( Popup ): self.drumBox.append_item(instrument, text = None, icon_name = image, size = instrumentPalette.ICON_SIZE) def getDrums(self): - return sorted([instrument for instrument in Config.INSTRUMENTS.keys() if Config.INSTRUMENTS[instrument].kit]) - + return sorted([instrument for instrument in self.instrumentDB.instNamed.keys() if self.instrumentDB.instNamed[instrument].kit]) + def setBlock( self, widget = None, event = None, block = None ): if self.is_up(): self.popdown(True) else: self.popup( True ) - - diff --git a/TamTamJam.activity/Jam/GenRythm.py b/TamTamJam.activity/Jam/GenRythm.py index 330e174..b9e6d48 100644 --- a/TamTamJam.activity/Jam/GenRythm.py +++ b/TamTamJam.activity/Jam/GenRythm.py @@ -1,10 +1,14 @@ import random import common.Config as Config +import common.Util.InstrumentDB as InstrumentDB from common.Generation.GenerationConstants import GenerationConstants from common.Generation.Utils import * class GenRythm: + def __init__(self): + self.instrumentDB = InstrumentDB.getRef() + def drumRythmSequence(self, instrumentName, nbeats, density, regularity ): rythmSequence = [] binSelection = [] @@ -14,28 +18,28 @@ class GenRythm: countDown = 0 onsetTime = None - if Config.INSTRUMENTS[instrumentName].instrumentRegister == Config.PUNCH: + if self.instrumentDB.instNamed[instrumentName].instrumentRegister == Config.PUNCH: registerDensity = 0.5 downBeatRecurence = 4 downBeats = [x for x in GenerationConstants.DRUM_PUNCH_ACCENTS[ nbeats ]] for downBeat in downBeats: upBeats.append( downBeat + Config.TICKS_PER_BEAT / 2 ) - if Config.INSTRUMENTS[instrumentName].instrumentRegister == Config.LOW: + if self.instrumentDB.instNamed[instrumentName].instrumentRegister == Config.LOW: registerDensity =1 downBeatRecurence = 4 downBeats = [x for x in GenerationConstants.DRUM_LOW_ACCENTS[ nbeats ]] for downBeat in downBeats: upBeats.append( downBeat + Config.TICKS_PER_BEAT / 2 ) - if Config.INSTRUMENTS[instrumentName].instrumentRegister == Config.MID: + if self.instrumentDB.instNamed[instrumentName].instrumentRegister == Config.MID: registerDensity = .75 downBeatRecurence = 1 downBeats = [x for x in GenerationConstants.DRUM_MID_ACCENTS[ nbeats ]] for downBeat in downBeats: upBeats.append( downBeat + Config.TICKS_PER_BEAT / 4 ) - if Config.INSTRUMENTS[instrumentName].instrumentRegister == Config.HIGH: + if self.instrumentDB.instNamed[instrumentName].instrumentRegister == Config.HIGH: registerDensity = 1.5 downBeatRecurence = 1 downBeats = [x for x in GenerationConstants.DRUM_HIGH_ACCENTS[ nbeats ]] @@ -48,10 +52,10 @@ class GenRythm: list = range( int( realDensity * len( downBeats ) ) ) for i in list: - if random.random() < ( regularity * downBeatRecurence ) and binSelection.count( 1 ) < len( downBeats ): - binSelection.append( 1 ) + if random.random() < ( regularity * downBeatRecurence ) and binSelection.count( 1 ) < len( downBeats ): + binSelection.append( 1 ) else: - if binSelection.count( 0 ) < len( downBeats ): + if binSelection.count( 0 ) < len( downBeats ): binSelection.append( 0 ) else: binSelection.append( 1 ) diff --git a/TamTamJam.activity/Jam/JamMain.py b/TamTamJam.activity/Jam/JamMain.py index f795008..dbd7f8b 100644 --- a/TamTamJam.activity/Jam/JamMain.py +++ b/TamTamJam.activity/Jam/JamMain.py @@ -6,6 +6,7 @@ import pango import os, sys, shutil +import common.Util.Instruments import common.Config as Config from gettext import gettext as _ import sugar.graphics.style as style @@ -173,7 +174,7 @@ class JamMain(gtk.EventBox): self.instrumentImage = {} self.instrumentImageActive = {} for inst in self.instrumentDB.getSet( "All" ): - self.prepareInstrumentImage( inst.id, inst.img ) + self.prepareInstrumentImage( inst.instrumentId, inst.img ) #-- Loop Images --------------------------------------- self.loopImage = {} # get filled in through updateLoopImage @@ -260,18 +261,18 @@ class JamMain(gtk.EventBox): self.keyMap = {} # default instrument - self._updateInstrument( Config.INSTRUMENTS["kalimba"].instrumentId, 0.5 ) + self._updateInstrument( self.instrumentDB.instNamed["kalimba"].instrumentId, 0.5 ) self.instrumentStack = [] # metronome page = NoteDB.Page( 1, local = False ) - self.metronomePage = self.noteDB.addPage( -1, page ) + self.metronomePage = self.noteDB.addPage( -1, page ) self.metronome = False #-- Drums --------------------------------------------- self.drumLoopId = None # use dummy values for now - self.drumFillin = Fillin( 2, 100, Config.INSTRUMENTS["drum1kit"].instrumentId, 0, 1 ) + self.drumFillin = Fillin( 2, 100, self.instrumentDB.instNamed["drum1kit"].instrumentId, 0, 1 ) #-- Desktops ------------------------------------------ self.curDesktop = None @@ -362,7 +363,7 @@ class JamMain(gtk.EventBox): if Config.KEY_MAP_PIANO.has_key( key ): pitch = Config.KEY_MAP_PIANO[key] - inst = Config.INSTRUMENTSID[self.instrument["id"]] + inst = self.instrumentDB.instId[self.instrument["id"]] if inst.kit: # drum kit if pitch in GenerationConstants.DRUMPITCH: @@ -426,7 +427,7 @@ class JamMain(gtk.EventBox): def _stopNote( self, key ): csnote = self.key_dict[key] - if Config.INSTRUMENTSID[ csnote.instrumentId ].csoundInstrumentId == Config.INST_TIED: + if self.instrumentDB.instId[ csnote.instrumentId ].csoundInstrumentId == Config.INST_TIED: csnote.duration = .5 csnote.decay = 0.7 csnote.tied = False @@ -476,7 +477,7 @@ class JamMain(gtk.EventBox): self.csnd.loopSetNumTicks( ticks, loopId ) self.drumFillin.setLoopId( loopId ) - self.drumFillin.setProperties( self.tempo, Config.INSTRUMENTSID[id].name, volume, beats, reverb ) + self.drumFillin.setProperties( self.tempo, self.instrumentDB.instId[id].name, volume, beats, reverb ) self.drumFillin.unavailable( noteOnsets, notePitchs ) self.drumFillin.play() @@ -527,7 +528,7 @@ class JamMain(gtk.EventBox): # TODO update track volume - inst = Config.INSTRUMENTSID[id] + inst = self.instrumentDB.instId[id] offset = 0 for page in tune: @@ -548,11 +549,11 @@ class JamMain(gtk.EventBox): self.csnd.loopSetNumTicks( offset, loopId ) - while startTick > offset: + while startTick > offset: startTick -= offset - + # sync to heartbeat - if sync: + if sync: beatTick = startTick % Config.TICKS_PER_BEAT syncTick = self.csnd.loopGetTick( self.heartbeatLoop ) % Config.TICKS_PER_BEAT if beatTick > syncTick: @@ -590,7 +591,7 @@ class JamMain(gtk.EventBox): 0.5, # pan 100, # duration 0, # track - Config.INSTRUMENTS["drum1hatpedal"].instrumentId, + self.instrumentDB.instNamed["drum1hatpedal"].instrumentId, reverbSend = 0.5, tied = True, mode = 'mini' ) @@ -600,12 +601,12 @@ class JamMain(gtk.EventBox): for b in range( self.noteDB.getPage( page ).beats ): cs = baseCS.clone() - cs.instrumentId = Config.INSTRUMENTS["drum1hatshoulder"].instrumentId + cs.instrumentId = self.instrumentDB.instNamed["drum1hatshoulder"].instrumentId cs.amplitude = 0.5 cs.onset += offset stream.append( cs ) - + onset = period while onset < Config.TICKS_PER_BEAT: cs = baseCS.clone() @@ -616,7 +617,7 @@ class JamMain(gtk.EventBox): offset += Config.TICKS_PER_BEAT self.noteDB.addNotes( [ page, 1, len(stream) ] + stream + [ -1 ] ) - + def removeMetronome( self, page ): self.noteDB.deleteNotesByTrack( [ page ], [ 1 ] ) @@ -634,14 +635,14 @@ class JamMain(gtk.EventBox): self.paused = True for loop in loops: self.csnd.loopPause( loop ) - - def setStopped( self ): + + def setStopped( self ): for drum in list(self.desktop.drums): self.desktop.deactivateDrum(drum) - + for loop in list(self.desktop.loops): # we copy the list using the list() method self.desktop.deactivateLoop(loop) - + #========================================================== @@ -654,7 +655,7 @@ class JamMain(gtk.EventBox): rval += l return rval - notes = flatten( generator( Config.INSTRUMENTSID[instrumentId].name, beats, 0.8, regularity, reverb) ) + notes = flatten( generator( self.instrumentDB.instId[instrumentId].name, beats, 0.8, regularity, reverb) ) if pageId == -1: page = Page( beats ) @@ -669,7 +670,7 @@ class JamMain(gtk.EventBox): def _generateTrack( self, instrumentId, page, track, parameters, algorithm ): dict = { track: { page: self.noteDB.getCSNotesByTrack( page, track ) } } - instruments = { page: [ Config.INSTRUMENTSID[instrumentId].name for i in range(Config.NUMBER_OF_TRACKS) ] } + instruments = { page: [ self.instrumentDB.instId[instrumentId].name for i in range(Config.NUMBER_OF_TRACKS) ] } beatsOfPages = { page: self.noteDB.getPage(page).beats } algorithm( parameters, @@ -1103,7 +1104,7 @@ class JamMain(gtk.EventBox): # Sync def setSyncBeats( self, beats ): - self.jamToolbar.setSyncBeats( beats ) + self.jamToolbar.setSyncBeats( beats ) def _setSyncBeats( self, beats ): if beats == self.syncBeats: @@ -1114,7 +1115,7 @@ class JamMain(gtk.EventBox): ticks = beats * Config.TICKS_PER_BEAT curTick = self.csnd.loopGetTick( self.heartbeatLoop ) - + self.csnd.loopSetNumTicks( ticks, self.heartbeatLoop ) while curTick > ticks: curTick -= ticks diff --git a/TamTamJam.activity/Jam/Picker.py b/TamTamJam.activity/Jam/Picker.py index 5609e56..731e85b 100644 --- a/TamTamJam.activity/Jam/Picker.py +++ b/TamTamJam.activity/Jam/Picker.py @@ -24,7 +24,7 @@ class Picker( gtk.HBox ): gtk.HBox.__init__( self ) self.owner = owner - + # take drawing setup from owner self.gc = owner.gc self.colors = owner.colors @@ -96,7 +96,7 @@ class Picker( gtk.HBox ): if self._testAgainstFilter( block ): self.pickerBox.pack_start( block, False, False, 3 ) - + block.show_all() return block @@ -159,7 +159,7 @@ class Picker( gtk.HBox ): class Instrument( Picker ): - + def __init__( self, owner, filter = ( "All" ) ): Picker.__init__( self, owner, filter ) @@ -168,12 +168,12 @@ class Instrument( Picker ): self.instrumentDB = InstrumentDB.getRef() for inst in self.instrumentDB.getSet( "All" ): - self.addBlock( inst.id ) + self.addBlock( inst.instrumentId ) def addBlock( self, id ): # match data structure of Block.Instrument - data = { "name": _(Config.INSTRUMENTSID[id].name), - "id": id } + data = { "name": _(self.instrumentDB.instId[id].name), + "id": id } win = gtk.gdk.get_default_root_window() width = Block.Instrument.WIDTH @@ -181,13 +181,13 @@ class Instrument( Picker ): pixmap = gtk.gdk.Pixmap( win, width, height ) self.gc.set_clip_rectangle( gtk.gdk.Rectangle( 0, 0, width, height ) ) - + # draw bg self.gc.foreground = self.colors["Picker_Bg"] pixmap.draw_rectangle( self.gc, True, 0, 0, width, height ) self.gc.set_clip_mask( self.blockMask ) - + # draw border self.gc.foreground = self.colors["Border_Inactive"] self.gc.set_clip_origin( -Block.Instrument.MASK_START, 0 ) @@ -196,7 +196,7 @@ class Instrument( Picker ): # draw block inst = self.owner.getInstrumentImage( data["id"] ) self.gc.set_clip_origin( -Block.Instrument.MASK_START, -height ) - pixmap.draw_drawable( self.gc, inst, 0, 0, 0, 0, width, height ) + pixmap.draw_drawable( self.gc, inst, 0, 0, 0, 0, width, height ) image = gtk.Image() image.set_from_pixmap( pixmap, None ) @@ -211,12 +211,11 @@ class Instrument( Picker ): if "All" in self.filter: return True - for label in self.instrumentDB.getInstrument( block.data["id"] ).labels: - if label in self.filter: - return True + if self.instrumentDB.getInstrument( block.data["id"] ).category in self.filter: + return True return False - + def on_button_press( self, widget, event ): walloc = widget.get_allocation() salloc = self.scrolledWindow.get_allocation() @@ -227,7 +226,7 @@ class Instrument( Picker ): class Drum( Picker ): - + def __init__( self, owner, filter = None ): Picker.__init__( self, owner, filter ) @@ -236,12 +235,12 @@ class Drum( Picker ): self.instrumentDB = InstrumentDB.getRef() for inst in self.instrumentDB.getSet( "percussions" ): - if Config.INSTRUMENTS[inst.name].kit: - self.addBlock( inst.id ) + if self.instrumentDB.instNamed[inst.name].kit: + self.addBlock( inst.instrumentId ) def addBlock( self, id ): # match data structure of Block.Drum - data = { "name": _(Config.INSTRUMENTSID[id].name), + data = { "name": _(self.instrumentDB.instId[id].name), "id": id } win = gtk.gdk.get_default_root_window() @@ -250,13 +249,13 @@ class Drum( Picker ): pixmap = gtk.gdk.Pixmap( win, width, height ) self.gc.set_clip_rectangle( gtk.gdk.Rectangle( 0, 0, width, height ) ) - + # draw bg self.gc.foreground = self.colors["Picker_Bg"] pixmap.draw_rectangle( self.gc, True, 0, 0, width, height ) self.gc.set_clip_mask( self.blockMask ) - + # draw border self.gc.foreground = self.colors["Border_Inactive"] self.gc.set_clip_origin( -Block.Drum.MASK_START, 0 ) @@ -265,7 +264,7 @@ class Drum( Picker ): # draw block inst = self.owner.getInstrumentImage( data["id"] ) self.gc.set_clip_origin( -Block.Drum.MASK_START, -height ) - pixmap.draw_drawable( self.gc, inst, 0, 0, 0, 0, width, height ) + pixmap.draw_drawable( self.gc, inst, 0, 0, 0, 0, width, height ) image = gtk.Image() image.set_from_pixmap( pixmap, None ) @@ -274,8 +273,8 @@ class Drum( Picker ): block.modify_bg( gtk.STATE_NORMAL, self.colors["Picker_Bg"] ) block.add( image ) - Picker.addBlock( self, data, data["name"], block ) - + Picker.addBlock( self, data, data["name"], block ) + def on_button_press( self, widget, event ): walloc = widget.get_allocation() salloc = self.scrolledWindow.get_allocation() @@ -284,16 +283,16 @@ class Drum( Picker ): class Loop( Picker ): - + def __init__( self, owner, filter = None ): Picker.__init__( self, owner, filter ) self.type = Loop self.presetLoops = self._scanDirectory( Config.FILES_DIR+"/Loops" ) - + def _loadFile( self, fullpath, filename ): - if filename[-4:] != ".ttl": + if filename[-4:] != ".ttl": if Config.DEBUG >= 3: print "WARNING: incorrect extension on loop file: " + filename return -1 try: @@ -310,15 +309,15 @@ class Loop( Picker ): if len(newPages) != 1: print "ERROR: bad loop file, contains more than one page (or none)" return -1 - + id = newPages.pop() # new pageId self.owner.noteDB.getPage( id ).setLocal( False ) # flag as a global page - + self.addBlock( id, filename[:-4] ) return id - + except OSError,e: print 'ERROR: failed to open file %s for reading\n' % ofilename return -1 @@ -334,11 +333,11 @@ class Loop( Picker ): def addBlock( self, id, name ): # match data structure of Block.Loop data = { "name": _(name), - "id": id } + "id": id } self.owner.updateLoopImage( data["id"] ) loop = self.owner.getLoopImage( data["id"] ) - + page = self.owner.noteDB.getPage( id ) win = gtk.gdk.get_default_root_window() @@ -347,14 +346,14 @@ class Loop( Picker ): pixmap = gtk.gdk.Pixmap( win, width, height ) self.gc.set_clip_rectangle( gtk.gdk.Rectangle( 0, 0, width, height ) ) - + # draw bg self.gc.foreground = self.colors["Picker_Bg"] pixmap.draw_rectangle( self.gc, True, 0, 0, width, height ) self.gc.set_clip_mask( self.blockMask ) self.gc.foreground = self.owner.colors["Border_Inactive"] - + #-- draw head ----------------------------------------- # draw border @@ -363,10 +362,10 @@ class Loop( Picker ): # draw block self.gc.set_clip_origin( -Block.Loop.MASK_START, -height ) - pixmap.draw_drawable( self.gc, loop, 0, 0, 0, 0, Block.Loop.HEAD, height ) + pixmap.draw_drawable( self.gc, loop, 0, 0, 0, 0, Block.Loop.HEAD, height ) #-- draw beats ---------------------------------------- - + beats = page.beats - 1 # last beat is drawn with the tail curx = Block.Loop.HEAD while beats > 3: @@ -376,13 +375,13 @@ class Loop( Picker ): # draw block self.gc.set_clip_origin( curx-Block.Loop.MASK_BEAT, -height ) - pixmap.draw_drawable( self.gc, loop, curx, 0, curx, 0, Block.Loop.BEAT_MUL3, height ) + pixmap.draw_drawable( self.gc, loop, curx, 0, curx, 0, Block.Loop.BEAT_MUL3, height ) curx += Block.Loop.BEAT_MUL3 beats -= 3 if beats: - w = Block.Loop.BEAT*beats + w = Block.Loop.BEAT*beats # draw border self.gc.set_clip_origin( curx-Block.Loop.MASK_BEAT, 0 ) @@ -390,9 +389,9 @@ class Loop( Picker ): # draw block self.gc.set_clip_origin( curx-Block.Loop.MASK_BEAT, -height ) - pixmap.draw_drawable( self.gc, loop, curx, 0, curx, 0, w, height ) + pixmap.draw_drawable( self.gc, loop, curx, 0, curx, 0, w, height ) - curx += w + curx += w #-- draw tail ----------------------------------------- @@ -402,7 +401,7 @@ class Loop( Picker ): # draw block self.gc.set_clip_origin( curx-Block.Loop.MASK_TAIL, -height ) - pixmap.draw_drawable( self.gc, loop, curx, 0, curx, 0, Block.Loop.TAIL, height ) + pixmap.draw_drawable( self.gc, loop, curx, 0, curx, 0, Block.Loop.TAIL, height ) image = gtk.Image() image.set_from_pixmap( pixmap, None ) @@ -411,8 +410,8 @@ class Loop( Picker ): block.modify_bg( gtk.STATE_NORMAL, self.colors["Picker_Bg"] ) block.add( image ) - Picker.addBlock( self, data, data["name"], block ) - + Picker.addBlock( self, data, data["name"], block ) + def on_button_press( self, widget, event ): walloc = widget.get_allocation() salloc = self.scrolledWindow.get_allocation() @@ -422,10 +421,8 @@ class Loop( Picker ): for key in widget.data.keys(): data[key] = widget.data[key] - newid = self.owner.noteDB.duplicatePages( [ data["id"] ] )[data["id"]] + newid = self.owner.noteDB.duplicatePages( [ data["id"] ] )[data["id"]] self.owner.updateLoopImage( newid ) data["id"] = newid block = self.desktop.addBlock( Block.Loop, data, loc, True ) - - diff --git a/TamTamJam.activity/Jam/RythmGenerator.py b/TamTamJam.activity/Jam/RythmGenerator.py index 537f598..d1ea46e 100644 --- a/TamTamJam.activity/Jam/RythmGenerator.py +++ b/TamTamJam.activity/Jam/RythmGenerator.py @@ -1,10 +1,13 @@ import random +import common.Util.InstrumentDB as InstrumentDB import common.Config as Config from common.Util.CSoundNote import CSoundNote from common.Generation.GenerationConstants import GenerationConstants from GenRythm import GenRythm +instrumentDB = InstrumentDB.getRef() + def generator( instrument, nbeats, density, regularity, reverbSend ): makeRythm = GenRythm() @@ -18,15 +21,15 @@ def generator( instrument, nbeats, density, regularity, reverbSend ): filterCutoff = 1000 tied = False mode = 'mini' - + def makePitchSequence(length, drumPitch): pitchSequence = [] append = pitchSequence.append list = range(length) max = len(drumPitch) - 1 for i in list: - append(drumPitch[ random.randint( 0, max ) ] ) - return pitchSequence + append(drumPitch[ random.randint( 0, max ) ] ) + return pitchSequence def makeGainSequence( onsetList ): gainSequence = [] @@ -36,16 +39,16 @@ def generator( instrument, nbeats, density, regularity, reverbSend ): gain = random.uniform(GenerationConstants.GAIN_MID_MAX_BOUNDARY, GenerationConstants.GAIN_MAX_BOUNDARY) elif ( onset % Config.TICKS_PER_BEAT) == 0: gain = random.uniform(GenerationConstants.GAIN_MID_MIN_BOUNDARY, GenerationConstants.GAIN_MID_MAX_BOUNDARY) - else: + else: gain = random.uniform(GenerationConstants.GAIN_MIN_BOUNDARY, GenerationConstants.GAIN_MID_MIN_BOUNDARY) append(gain) - return gainSequence - + return gainSequence + def pageGenerate( regularity, drumPitch ): barLength = Config.TICKS_PER_BEAT * nbeats #print 'pageGenerate drumPitch[0] ', drumPitch[0] - currentInstrument = Config.INSTRUMENTS[ instrument ].kit[ drumPitch[0] ].name + currentInstrument = instrumentDB.instNamed[ instrument ].kit[ drumPitch[0] ] rythmSequence = makeRythm.drumRythmSequence(currentInstrument, nbeats, density, regularity) pitchSequence = makePitchSequence(len(rythmSequence), drumPitch ) @@ -54,16 +57,16 @@ def generator( instrument, nbeats, density, regularity, reverbSend ): trackNotes = [] list = range(len(rythmSequence)) for i in list: - trackNotes.append( CSoundNote( rythmSequence[i], pitchSequence[i], gainSequence[i], - pan, noteDuration, trackId, - Config.INSTRUMENTS[instrument].instrumentId, attack, + trackNotes.append( CSoundNote( rythmSequence[i], pitchSequence[i], gainSequence[i], + pan, noteDuration, trackId, + instrumentDB.instNamed[instrument].instrumentId, attack, decay, reverbSend, filterType, filterCutoff, tied, mode)) return trackNotes -################################################################################## - # begin generate() +################################################################################## + # begin generate() if regularity > 0.75: - streamOfPitch = GenerationConstants.DRUM_COMPLEXITY1 + streamOfPitch = GenerationConstants.DRUM_COMPLEXITY1 elif regularity > 0.5: streamOfPitch = GenerationConstants.DRUM_COMPLEXITY2 elif regularity > 0.25: diff --git a/TamTamMini.activity/Mini/GenRythm.py b/TamTamMini.activity/Mini/GenRythm.py index 330e174..7d67994 100644 --- a/TamTamMini.activity/Mini/GenRythm.py +++ b/TamTamMini.activity/Mini/GenRythm.py @@ -3,9 +3,11 @@ import common.Config as Config from common.Generation.GenerationConstants import GenerationConstants from common.Generation.Utils import * +from common.Util import InstrumentDB class GenRythm: def drumRythmSequence(self, instrumentName, nbeats, density, regularity ): + instrumentDB = InstrumentDB.getRef() rythmSequence = [] binSelection = [] downBeats = [] @@ -14,28 +16,28 @@ class GenRythm: countDown = 0 onsetTime = None - if Config.INSTRUMENTS[instrumentName].instrumentRegister == Config.PUNCH: + if instrumentDB.instNamed[instrumentName].instrumentRegister == Config.PUNCH: registerDensity = 0.5 downBeatRecurence = 4 downBeats = [x for x in GenerationConstants.DRUM_PUNCH_ACCENTS[ nbeats ]] for downBeat in downBeats: upBeats.append( downBeat + Config.TICKS_PER_BEAT / 2 ) - if Config.INSTRUMENTS[instrumentName].instrumentRegister == Config.LOW: + if instrumentDB.instNamed[instrumentName].instrumentRegister == Config.LOW: registerDensity =1 downBeatRecurence = 4 downBeats = [x for x in GenerationConstants.DRUM_LOW_ACCENTS[ nbeats ]] for downBeat in downBeats: upBeats.append( downBeat + Config.TICKS_PER_BEAT / 2 ) - if Config.INSTRUMENTS[instrumentName].instrumentRegister == Config.MID: + if instrumentDB.instNamed[instrumentName].instrumentRegister == Config.MID: registerDensity = .75 downBeatRecurence = 1 downBeats = [x for x in GenerationConstants.DRUM_MID_ACCENTS[ nbeats ]] for downBeat in downBeats: upBeats.append( downBeat + Config.TICKS_PER_BEAT / 4 ) - if Config.INSTRUMENTS[instrumentName].instrumentRegister == Config.HIGH: + if instrumentDB.instNamed[instrumentName].instrumentRegister == Config.HIGH: registerDensity = 1.5 downBeatRecurence = 1 downBeats = [x for x in GenerationConstants.DRUM_HIGH_ACCENTS[ nbeats ]] @@ -48,10 +50,10 @@ class GenRythm: list = range( int( realDensity * len( downBeats ) ) ) for i in list: - if random.random() < ( regularity * downBeatRecurence ) and binSelection.count( 1 ) < len( downBeats ): - binSelection.append( 1 ) + if random.random() < ( regularity * downBeatRecurence ) and binSelection.count( 1 ) < len( downBeats ): + binSelection.append( 1 ) else: - if binSelection.count( 0 ) < len( downBeats ): + if binSelection.count( 0 ) < len( downBeats ): binSelection.append( 0 ) else: binSelection.append( 1 ) diff --git a/TamTamMini.activity/Mini/InstrumentPanel.py b/TamTamMini.activity/Mini/InstrumentPanel.py index 8cac210..b28e969 100644 --- a/TamTamMini.activity/Mini/InstrumentPanel.py +++ b/TamTamMini.activity/Mini/InstrumentPanel.py @@ -8,12 +8,15 @@ import time import common.Config as Config from common.Util.ThemeWidgets import * +from common.Util import InstrumentDB + Tooltips = Config.Tooltips class InstrumentPanel( gtk.EventBox ): def __init__(self,setInstrument = None, playInstrument = None, enterMode = False, micRec = None, synthRec = None, rowLen = 8, _instDic = None, force_load = True ): gtk.EventBox.__init__(self) + self.instrumentDB = InstrumentDB.getRef() self.setInstrument = setInstrument self.playInstrument = playInstrument self.micRec = micRec @@ -116,10 +119,10 @@ class InstrumentPanel( gtk.EventBox ): if timeout >= 0 and time.time() > timeout: return False if loadStage[1] == 1: - keys = Config.INSTRUMENTS.keys() + keys = self.instrumentDB.instNamed.keys() for i in range(loadStage[2], len(keys)): key = keys[i] - instrument = Config.INSTRUMENTS[key] + instrument = self.instrumentDB.instNamed[key] if key[0:4] != 'drum' and key[0:4] != 'guid' and key[0:3] != 'mic' and key[0:3] != 'lab': self.instrumentList["all"].append( key ) if key[0:4] != 'drum' and key[0:4] != 'guid' and key[0:3] != 'mic' and key[0:3] != 'lab': @@ -333,9 +336,9 @@ class DrumPanel( gtk.EventBox ): self.setDrum = setDrum self.instrumentList = [] - keys = Config.INSTRUMENTS.keys() - for key in Config.INSTRUMENTS.keys(): - if Config.INSTRUMENTS[key].category == "kit": + keys = self.instrumentDB.instNamed.keys() + for key in keys: + if self.instrumentDB.instNamed[key].category == "kit": self.instrumentList.append( key ) self.instrumentList.sort() self.drawDrums() diff --git a/TamTamMini.activity/Mini/KeyboardStandAlone.py b/TamTamMini.activity/Mini/KeyboardStandAlone.py index e3c3424..cc86a31 100644 --- a/TamTamMini.activity/Mini/KeyboardStandAlone.py +++ b/TamTamMini.activity/Mini/KeyboardStandAlone.py @@ -7,6 +7,7 @@ from common.Generation.GenerationConstants import GenerationConstants from common.Util.NoteDB import Note from common.Util.CSoundNote import CSoundNote from common.Util.CSoundClient import new_csound_client +from common.Util import InstrumentDB KEY_MAP_PIANO = Config.KEY_MAP_PIANO @@ -14,6 +15,7 @@ KEY_MAP_PIANO = Config.KEY_MAP_PIANO class KeyboardStandAlone: def __init__( self, recordingFunction, adjustDurationFunction, getCurrentTick, getPlayState, loop ): + self.instrumentDB = InstrumentDB.getRef() self.csnd = new_csound_client() self.recording = recordingFunction self.adjustDuration = adjustDurationFunction @@ -93,17 +95,17 @@ class KeyboardStandAlone: #print >>log, 'instrumentName:', instrumentName pitch = KEY_MAP_PIANO[key] - if None != Config.INSTRUMENTS[instrumentName].kit: + if self.instrumentDB.instNamed[instrumentName].kit != None: if pitch in GenerationConstants.DRUMPITCH: pitch = GenerationConstants.DRUMPITCH[pitch] - #print >>log, 'kit_element: ', Config.KIT_ELEMENT[pitch] - playkey(36,100, Config.INSTRUMENTS[instrumentName].kit[pitch]) + #print >>log, 'kit_element: ', Config.KIT_ELEMENT[pitch] + playkey(36,100, self.instrumentDB.instNamed[instrumentName].kit[pitch]) else: if event.state == gtk.gdk.MOD1_MASK: pitch += 5 - instrument = Config.INSTRUMENTS[ instrumentName ] + instrument = self.instrumentDB.instNamed[ instrumentName ] if instrument.csoundInstrumentId == Config.INST_PERC: #Percussions resonance playkey( pitch, 60, instrument) else: @@ -124,7 +126,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 self.instrumentDB.instId[ csnote.instrumentId ].csoundInstrumentId == Config.INST_TIED: csnote.duration = .5 csnote.decay = 0.7 #csnote.amplitude = 1 diff --git a/TamTamMini.activity/Mini/Loop.py b/TamTamMini.activity/Mini/Loop.py index 4f58912..27ac46c 100755 --- a/TamTamMini.activity/Mini/Loop.py +++ b/TamTamMini.activity/Mini/Loop.py @@ -7,9 +7,11 @@ from common.Util.CSoundClient import new_csound_client from common.Util.NoteDB import Note from common.Util.NoteDB import PARAMETER from common.Generation.GenerationConstants import GenerationConstants +from common.Util import InstrumentDB class Loop: def __init__( self, beat, volume ): + self.instrumentDB = InstrumentDB.getRef() self.notesDict = {} self.notesList = [] self.beat = beat @@ -49,10 +51,10 @@ class Loop: pitch = i[1] gain = i[2]*self.volume duration = i[3] - if Config.INSTRUMENTS[instrument].kit != None: + if self.instrumentDB.instNamed[instrument].kit != None: if GenerationConstants.DRUMPITCH.has_key(pitch): pitch = GenerationConstants.DRUMPITCH[pitch] - instrument = Config.INSTRUMENTS[ instrument ].kit[pitch].name + instrument = self.instrumentDB.instNamed[ instrument ].kit[pitch].name pitch = 36 return CSoundNote( onset = onset, pitch = pitch, @@ -60,7 +62,7 @@ class Loop: pan = 0.5, duration = duration, trackId = 0, - instrumentId = Config.INSTRUMENTS[instrument].instrumentId, + instrumentId = self.instrumentDB.instNamed[instrument].instrumentId, reverbSend = reverb, tied = False, mode = 'mini') diff --git a/TamTamMini.activity/Mini/NoteStdAlone.py b/TamTamMini.activity/Mini/NoteStdAlone.py index 0dd4638..d007da9 100644 --- a/TamTamMini.activity/Mini/NoteStdAlone.py +++ b/TamTamMini.activity/Mini/NoteStdAlone.py @@ -4,18 +4,18 @@ from common.Generation.GenerationConstants import GenerationConstants class NoteStdAlone: def __init__( self, client, - onset, - pitch, - amplitude, - pan, - duration, - trackId, - fullDuration = False, - instrument = Config.FLUTE, - attack = 0.005, - decay = 0.095, - reverbSend = 0.1, - filterType = 0, + onset, + pitch, + amplitude, + pan, + duration, + trackId, + fullDuration = False, + instrument = Config.FLUTE, + attack = 0.005, + decay = 0.095, + reverbSend = 0.1, + filterType = 0, filterCutoff = 1000, tied = False, overlap = False, @@ -43,7 +43,7 @@ class NoteStdAlone: def play( self ): self.csnd.sendText( self.getText(120) ) - + def getText( self, tempo ): if self.instrument[ 0: 4 ] == 'drum': if GenerationConstants.DRUMPITCH.has_key( self.pitch ): @@ -65,10 +65,10 @@ class NoteStdAlone: newDuration = oneTickDuration * self.duration # condition for tied notes - if Config.INSTRUMENTS[ self.instrumentFlag ].csoundInstrumentId == 101 and self.tied and self.fullDuration: + if self.instrumentDB.instNamed[ self.instrumentFlag ].csoundInstrumentId == 101 and self.tied and self.fullDuration: newDuration = -1 # condition for overlaped notes - if Config.INSTRUMENTS[ self.instrumentFlag ].csoundInstrumentId == 102 and self.overlap: + if self.instrumentDB.instNamed[ self.instrumentFlag ].csoundInstrumentId == 102 and self.overlap: newDuration = oneTickDuration * self.duration + 1. if True: newAmplitude = self.amplitude * 0.8 @@ -82,22 +82,22 @@ class NoteStdAlone: if newDecay <= 0.002: newDecay = 0.002 - loopStart = Config.INSTRUMENTS[ self.instrumentFlag ].loopStart - loopEnd = Config.INSTRUMENTS[ self.instrumentFlag ].loopEnd - crossDur = Config.INSTRUMENTS[ self.instrumentFlag ].crossDur - return Config.PLAY_NOTE_COMMAND % ( Config.INSTRUMENTS[ self.instrumentFlag ].csoundInstrumentId, - self.trackId, + loopStart = self.instrumentDB.instNamed[ self.instrumentFlag ].loopStart + loopEnd = self.instrumentDB.instNamed[ self.instrumentFlag ].loopEnd + crossDur = self.instrumentDB.instNamed[ self.instrumentFlag ].crossDur + return Config.PLAY_NOTE_COMMAND % ( self.instrumentDB.instNamed[ self.instrumentFlag ].csoundInstrumentId, + self.trackId, 0, - newDuration, - newPitch, - self.reverbSend, - newAmplitude, - self.pan, - Config.INSTRUMENT_TABLE_OFFSET + Config.INSTRUMENTS[ self.instrumentFlag ].instrumentId, + newDuration, + newPitch, + self.reverbSend, + newAmplitude, + self.pan, + Config.INSTRUMENT_TABLE_OFFSET + self.instrumentDB.instNamed[ self.instrumentFlag ].instrumentId, newAttack, newDecay, self.filterType, self.filterCutoff, - loopStart, - loopEnd, - crossDur ) + loopStart, + loopEnd, + crossDur ) diff --git a/TamTamMini.activity/Mini/RythmGenerator.py b/TamTamMini.activity/Mini/RythmGenerator.py index 537f598..11df96e 100644 --- a/TamTamMini.activity/Mini/RythmGenerator.py +++ b/TamTamMini.activity/Mini/RythmGenerator.py @@ -4,9 +4,11 @@ import common.Config as Config from common.Util.CSoundNote import CSoundNote from common.Generation.GenerationConstants import GenerationConstants from GenRythm import GenRythm +from common.Util import InstrumentDB def generator( instrument, nbeats, density, regularity, reverbSend ): + instrumentDB = InstrumentDB.getRef() makeRythm = GenRythm() noteDuration = GenerationConstants.DOUBLE_TICK_DUR / 2 @@ -18,15 +20,15 @@ def generator( instrument, nbeats, density, regularity, reverbSend ): filterCutoff = 1000 tied = False mode = 'mini' - + def makePitchSequence(length, drumPitch): pitchSequence = [] append = pitchSequence.append list = range(length) max = len(drumPitch) - 1 for i in list: - append(drumPitch[ random.randint( 0, max ) ] ) - return pitchSequence + append(drumPitch[ random.randint( 0, max ) ] ) + return pitchSequence def makeGainSequence( onsetList ): gainSequence = [] @@ -36,16 +38,16 @@ def generator( instrument, nbeats, density, regularity, reverbSend ): gain = random.uniform(GenerationConstants.GAIN_MID_MAX_BOUNDARY, GenerationConstants.GAIN_MAX_BOUNDARY) elif ( onset % Config.TICKS_PER_BEAT) == 0: gain = random.uniform(GenerationConstants.GAIN_MID_MIN_BOUNDARY, GenerationConstants.GAIN_MID_MAX_BOUNDARY) - else: + else: gain = random.uniform(GenerationConstants.GAIN_MIN_BOUNDARY, GenerationConstants.GAIN_MID_MIN_BOUNDARY) append(gain) - return gainSequence - + return gainSequence + def pageGenerate( regularity, drumPitch ): barLength = Config.TICKS_PER_BEAT * nbeats #print 'pageGenerate drumPitch[0] ', drumPitch[0] - currentInstrument = Config.INSTRUMENTS[ instrument ].kit[ drumPitch[0] ].name + currentInstrument = instrumentDB.instNamed[ instrument ].kit[ drumPitch[0] ] #.name rythmSequence = makeRythm.drumRythmSequence(currentInstrument, nbeats, density, regularity) pitchSequence = makePitchSequence(len(rythmSequence), drumPitch ) @@ -54,16 +56,16 @@ def generator( instrument, nbeats, density, regularity, reverbSend ): trackNotes = [] list = range(len(rythmSequence)) for i in list: - trackNotes.append( CSoundNote( rythmSequence[i], pitchSequence[i], gainSequence[i], - pan, noteDuration, trackId, - Config.INSTRUMENTS[instrument].instrumentId, attack, + trackNotes.append( CSoundNote( rythmSequence[i], pitchSequence[i], gainSequence[i], + pan, noteDuration, trackId, + instrumentDB.instNamed[instrument].instrumentId, attack, decay, reverbSend, filterType, filterCutoff, tied, mode)) return trackNotes -################################################################################## - # begin generate() +################################################################################## + # begin generate() if regularity > 0.75: - streamOfPitch = GenerationConstants.DRUM_COMPLEXITY1 + streamOfPitch = GenerationConstants.DRUM_COMPLEXITY1 elif regularity > 0.5: streamOfPitch = GenerationConstants.DRUM_COMPLEXITY2 elif regularity > 0.25: diff --git a/TamTamMini.activity/Mini/miniTamTamMain.py b/TamTamMini.activity/Mini/miniTamTamMain.py index 1f9048e..c410a86 100644 --- a/TamTamMini.activity/Mini/miniTamTamMain.py +++ b/TamTamMini.activity/Mini/miniTamTamMain.py @@ -24,6 +24,7 @@ from common.Util import NoteDB from common.Util.NoteDB import Note from common.Util.CSoundClient import new_csound_client from common.Util.LoopSettings import LoopSettings +from common.Util import InstrumentDB from Fillin import Fillin from KeyboardStandAlone import KeyboardStandAlone @@ -46,6 +47,7 @@ class miniTamTamMain(gtk.EventBox): self.set_border_width(Config.MAIN_WINDOW_PADDING) + self.instrumentDB = InstrumentDB.getRef() self.firstTime = False self.playing = False self.csnd = new_csound_client() @@ -564,7 +566,7 @@ class miniTamTamMain(gtk.EventBox): #data is drum1kit, drum2kit, or drum3kit #print 'HANDLE: Generate Button' self.rythmInstrument = data - instrumentId = Config.INSTRUMENTS[data].instrumentId + instrumentId = self.instrumentDB.instNamed[data].instrumentId for (o,n) in self.noteList : self.csnd.loopUpdate(n, NoteDB.PARAMETER.INSTRUMENT, instrumentId, -1) self.drumFillin.setInstrument( self.rythmInstrument ) @@ -595,7 +597,7 @@ class miniTamTamMain(gtk.EventBox): pan = 0.5, duration = 20, trackId = 1, - instrumentId = Config.INSTRUMENTS[instrument].instrumentId, + instrumentId = self.instrumentDB.instNamed[instrument].instrumentId, reverbSend = self.reverb, tied = False, mode = 'mini'), diff --git a/TamTamMini.activity/TamTamMini.py b/TamTamMini.activity/TamTamMini.py index 6823ced..404a7d1 100644 --- a/TamTamMini.activity/TamTamMini.py +++ b/TamTamMini.activity/TamTamMini.py @@ -8,6 +8,7 @@ import gtk import gobject import time +import common.Util.Instruments import common.Config as Config from common.Util.CSoundClient import new_csound_client from common.Util.Profiler import TP @@ -60,7 +61,7 @@ class TamTamMini(activity.Activity): self.mini.setInstrumentPanel( self.instrumentPanel ) self.set_canvas( self.mini ) - + self.mini.onActivate(arg = None) self.show() @@ -78,7 +79,7 @@ class TamTamMini(activity.Activity): if Config.DEBUG > 4: print "TamTam::preload returned after", time.time() - t return True - + def onActive(self, widget = None, event = None): if widget.props.active == False: csnd = new_csound_client() @@ -86,7 +87,7 @@ class TamTamMini(activity.Activity): else: csnd = new_csound_client() csnd.connect(True) - + def onKeyPress(self, widget, event): pass @@ -129,7 +130,7 @@ class TamTamMini(activity.Activity): def read_file(self,file_path): self.metadata['tamtam_subactivity'] = 'mini' - + def write_file(self,file_path): f = open(file_path,'w') - f.close() + f.close() diff --git a/TamTamSynthLab.activity/SynthLab/SynthLabMain.py b/TamTamSynthLab.activity/SynthLab/SynthLabMain.py index 6622076..4aeb60a 100644 --- a/TamTamSynthLab.activity/SynthLab/SynthLabMain.py +++ b/TamTamSynthLab.activity/SynthLab/SynthLabMain.py @@ -14,6 +14,8 @@ import commands from sugar.graphics.toolcombobox import ToolComboBox from common.Util.ThemeWidgets import BigComboBox +import common.Util.Instruments +import common.Util.InstrumentDB as InstrumentDB import common.Config as Config from common.Util.ThemeWidgets import * from common.Util.CSoundClient import new_csound_client @@ -35,6 +37,7 @@ class SynthLabMain(gtk.EventBox): self.set_keep_above(False) self.set_decorated(False) self.activity = activity + self.instrumentDB = InstrumentDB.getRef() self.csnd = new_csound_client() self.csnd.setMasterVolume( 100.0 ) # csnd expects a range 0-100 for now self.trackpad = Trackpad( self ) @@ -72,11 +75,14 @@ class SynthLabMain(gtk.EventBox): self._presetToolbar.show() loopPointsTable = [] - sample_names = [name for i in range( len( Config.INSTRUMENTS ) ) for name in Config.INSTRUMENTS.keys() if Config.INSTRUMENTS[ name ].instrumentId == i ] - for inst in sample_names: - loopStart = Config.INSTRUMENTS[ inst ].loopStart - loopEnd = Config.INSTRUMENTS[ inst ].loopEnd - crossDur = Config.INSTRUMENTS[ inst ].crossDur + self.sample_names = [name for i in range( len( self.instrumentDB.instNamed ) ) for name in self.instrumentDB.instNamed.keys() if self.instrumentDB.instNamed[ name ].instrumentId == i ] + print self.instrumentDB.instNamed + print self.sample_names + for inst in self.sample_names: + print self.instrumentDB.instNamed[ inst ].instrumentId + loopStart = self.instrumentDB.instNamed[ inst ].loopStart + loopEnd = self.instrumentDB.instNamed[ inst ].loopEnd + crossDur = self.instrumentDB.instNamed[ inst ].crossDur loopPointsTable.extend( [ loopStart, loopEnd, crossDur ] ) mess = "f5755 0 512 -2 " + " " .join([str(n) for n in loopPointsTable]) self.csnd.inputMessage( mess ) @@ -86,7 +92,7 @@ class SynthLabMain(gtk.EventBox): self.lineWidthMUL4 = self.lineWidth*4 self.lineWidthMUL4SQ = self.lineWidthMUL4*self.lineWidthMUL4 self.clockStart = 0 - self.sample_names = [name for i in range( len( Config.INSTRUMENTS ) ) for name in Config.INSTRUMENTS.keys() if Config.INSTRUMENTS[ name ].instrumentId == i ] + #self.sample_names = [name for i in range( len( Config.INSTRUMENTS ) ) for name in Config.INSTRUMENTS.keys() if Config.INSTRUMENTS[ name ].instrumentId == i ] if as_window: self.add_events(gtk.gdk.KEY_PRESS_MASK|gtk.gdk.KEY_RELEASE_MASK) diff --git a/common/Config.py b/common/Config.py index d583f16..2aae053 100644 --- a/common/Config.py +++ b/common/Config.py @@ -1,10 +1,9 @@ # -*- coding: utf-8 -*- import os -import common.Util.InstrumentDB as InstrumentDB from sugar.activity.activity import get_bundle_path from sugar import env -QUICKLOAD = os.path.isfile("QUICKLOAD") # skip loading inessential comenents to speed things up +#QUICKLOAD = os.path.isfile("QUICKLOAD") # skip loading inessential comenents to speed things up SugarMode = True @@ -52,48 +51,17 @@ PLUGIN_VERBOSE = 0 PLUGIN_UNIVORC = TAM_TAM_ROOT + "/common/Resources/tamtamorc.csd" PLUGIN_KSMPS = 64 PLUGIN_RATE = 16000 -#PLUGIN_KSMPS = 64 -#PLUGIN_RATE = 22050 ## PLUGIN ALSA PARAMETERS: - -## for macbook pro -#PLUGIN_PERIOD = 1024 -#PLUGIN_NPERIODS = 4 - -## for XO with root -#PLUGIN_PERIOD = 256 -#PLUGIN_NPERIODS = 2 - -## for XO as normal user PLUGIN_PERIOD = 256 #512 PLUGIN_NPERIODS = 2 ############## ## SOUNDS ############## -KIT_ELEMENT = 24 * [0] -for i in range(0,13): - KIT_ELEMENT += 2 * [i] -KIT_ELEMENT = tuple(KIT_ELEMENT) - -class Instrument: - def __init__( self, name, instrumentId, csoundInstrumentId, instrumentRegister, category, loopStart, loopEnd, crossDur, ampScale = 1, kit = None ): - self.name = name - self.instrumentId = instrumentId - self.csoundInstrumentId = csoundInstrumentId - self.instrumentRegister = instrumentRegister - self.category = category - self.loopStart = loopStart - self.loopEnd = loopEnd - self.crossDur = crossDur - self.ampScale = ampScale - self.kit = kit LOW, MID, HIGH, PUNCH = range( 4 ) -# Sounds categories: musicInst, animals, drum, people, electronic, concret, mic -#INSTRUMENTS ( csound table, csound instrument, register, instrumentClass, category ) INSTRUMENT_TABLE_OFFSET = 5000 INST_FREE = 5000 INST_TIED = 5001 @@ -102,279 +70,15 @@ INST_PERC = 5021 CATEGORIES = ['all','animals','concret','keyboard','people','percussions','strings','winds', 'mysounds'] -instrumentDB = InstrumentDB.getRef() - -_nextInstrumentId = [0] -INSTRUMENTS = {} -def _addInstrument( name, csoundInstrumentId, instrumentRegister, category, loopStart, loopEnd, crossDur, ampScale = 1, kit = None ): - if not QUICKLOAD or name[0:4] == "drum" or name in ["flute", "kalimba"]: # quick load - INSTRUMENTS[name] = Instrument( name, _nextInstrumentId[0], csoundInstrumentId, instrumentRegister, category, loopStart, loopEnd, crossDur, ampScale, kit ) - instrumentDB.addInstrumentFromArgs( name, csoundInstrumentId, instrumentRegister, loopStart, loopEnd, crossDur, ampScale, name, LIB_DIR+"/Images/"+name+".png", [ category ] ) - _nextInstrumentId[0] += 1 - - -_addInstrument( "mic1", INST_TIED, MID, 'mysounds', .01, 1.99, .01, 1 ) -_addInstrument( "mic2", INST_TIED, MID, 'mysounds', .01, 1.99, .01, 1 ) -_addInstrument( "mic3", INST_TIED, MID, 'mysounds', .01, 1.99, .01, 1 ) -_addInstrument( "mic4", INST_TIED, MID, 'mysounds', .01, 1.99, .01, 1 ) -_addInstrument( "lab1", INST_SIMP, MID, 'mysounds', 0, 0, 0, 1 ) -_addInstrument( "lab2", INST_SIMP, MID, 'mysounds', 0, 0, 0, 1 ) -_addInstrument( "lab3", INST_SIMP, MID, 'mysounds', 0, 0, 0, 1 ) -_addInstrument( "lab4", INST_SIMP, MID, 'mysounds', 0, 0, 0, 1 ) -_addInstrument( "lab5", INST_SIMP, MID, 'mysounds', 0, 0, 0, 1 ) -_addInstrument( "lab6", INST_SIMP, MID, 'mysounds', 0, 0, 0, 1 ) -_addInstrument( "ounk", INST_SIMP, MID, 'animals', 0, 0, 0, 1 ) -_addInstrument( "gam", INST_TIED, HIGH, 'percussions', .69388, .7536, .02922, 1 ) -_addInstrument( "guit", INST_TIED, MID, 'strings', .08592, .75126, .33571, 1.3 ) -_addInstrument( "koto", INST_TIED, HIGH, 'strings', .56523, .70075, .05954, 1 ) -_addInstrument( "clarinette", INST_TIED, MID, 'winds', 1.635276375, 2.72956523438, .2, 0.6 ) -_addInstrument( "flute", INST_TIED, MID, 'winds', .47169, .53693, .02481, 1 ) -_addInstrument( "drum1hatpedal", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum1hatshoulder", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum1hardride", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum1ridebell", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum1snare", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum1snaresidestick", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum1crash", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum1splash", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum1tom", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum1floortom", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1) -_addInstrument( "drum1chine", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum1kick", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "piano", INST_TIED, MID, 'keyboard', 0.8883, 1.420524, .13575, 1 ) -_addInstrument( "dog", INST_SIMP, MID, 'animals', 0, 0, 0, 1 ) -_addInstrument( "duck", INST_SIMP, MID, 'animals', 0, 0, 0, 1 ) -_addInstrument( "drum2darbukadoom", INST_SIMP, LOW, 'percussions', 0, 0 ,0, 1 ) -_addInstrument( "drum2darbukapied", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum2darbukapiedsoft", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum2hatflanger", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum2darbukatak", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum2darbukafinger", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum2darbukaroll", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum2darbukaslap", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum2hatpied", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum2tambourinepied", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum2hatpied2", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum2tambourinepiedsoft", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum3cowbell", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum3cowbelltip", INST_SIMP, MID, 'percussions', 0, 0, 0, 1) -_addInstrument( "drum3cup", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum3djembelow", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum3djembemid", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum3djembesidestick", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum3djembeslap", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum3djembestickmid", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum3metalstand", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum3pedalperc", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum3rainstick", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum3tambourinehigh", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum3tambourinelow", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "harmonica", INST_TIED, MID, 'winds', .1531, .19188, .01792, 1 ) -_addInstrument( "alarm", INST_TIED, MID, 'concret', 1.37555859375, 2.0286015625, .0675, 0.5 ) -_addInstrument( "bird", INST_TIED, MID, 'animals', .1, 1, .05, 1 ) -_addInstrument( "cat", INST_SIMP, MID, 'animals', 0, 0, 0, 1 ) -_addInstrument( "duck2", INST_SIMP, MID, 'animals', 0, 0, 0, 1 ) -_addInstrument( "bottle", INST_TIED, MID, 'concret', .20532, .41064, .05292, 1 ) -_addInstrument( "clang", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) -_addInstrument( "ow", INST_SIMP, MID, 'people', 0, 0, 0, 1 ) -_addInstrument( "sheep", INST_SIMP, MID, 'animals', 0, 0, 0, 1 ) -_addInstrument( "water", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) -_addInstrument( "zap", INST_TIED, MID, 'keyboard', .299, .7323, .09895, 1 ) -_addInstrument( "trumpet", INST_TIED, MID, 'winds', .91195, 1.652909375, .05375, 0.5) -_addInstrument( "bubbles", INST_TIED, MID, 'concret', 0.02, 1.177, 0.02, 1) -_addInstrument( "marimba", INST_TIED, MID, 'percussions', .18883789, .343623047, .07625, 0.5) -_addInstrument( "triangle", INST_TIED, MID, 'percussions', 2.27261836, 3.2965453, .2, 0.6) -_addInstrument( "laugh", INST_SIMP, MID, 'people', 0, 0, 0, 1 ) -_addInstrument( "voix", INST_TIED, MID, 'people', .89608, .96092, .02343, 1 ) -_addInstrument( "cling", INST_TIED, MID, 'keyboard', .09096, .7878, .18026, 1 ) -_addInstrument( "byke", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) -_addInstrument( "door", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) -_addInstrument( "basse", INST_TIED, MID, 'strings', 0.50470875, 0.833315, 0.09375, 1 ) -_addInstrument( "acguit", INST_TIED, MID, 'strings', 1.4037, 1.84235625, 0.2, 0.8 ) -_addInstrument( "diceinst", INST_SIMP, MID, 'concret', 0, 0, 0, 1.3 ) -_addInstrument( "didjeridu", INST_TIED, LOW, 'winds', .55669, 1.73704, .09178, 2 ) -_addInstrument( "harmonium", INST_TIED, MID, 'keyboard', .242032, .898165625, .2, 0.5 ) -_addInstrument( "horse", INST_SIMP, MID, 'animals', 0, 0, 0, 1 ) -_addInstrument( "kalimba", INST_TIED, MID, 'percussions', .20751, .30161, .04658, 1.3 ) -_addInstrument( "mando", INST_TIED, MID, 'strings', 0.507107031, 0.934144531, 0.2, 0.5 ) -_addInstrument( "ocarina", INST_TIED, MID, 'winds', .06612, .19033, .01776, 1 ) -_addInstrument( "rhodes", INST_TIED, MID, 'keyboard', 0.58100625, 0.821625, 0.067, 1 ) -_addInstrument( "saxo", INST_TIED, MID, 'winds', 1.161051953, 3.001209765, .05, 0.5 ) -_addInstrument( "shenai", INST_TIED, MID, 'winds', .29003, .33072, .00634, 0.7 ) -_addInstrument( "sitar", INST_TIED, MID, 'strings', 1.1361625, 1.575134375, .183, 0.4 ) -_addInstrument( "tuba", INST_TIED, LOW, 'winds', .51063, .58384, .035, 1 ) -_addInstrument( "violin", INST_TIED, MID, 'strings', .105, .30656, .028, 1 ) -_addInstrument( "guidice1", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) -_addInstrument( "guidice2", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) -_addInstrument( "guidice3", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) -_addInstrument( "guidice4", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) -_addInstrument( "guidice5", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) -_addInstrument( "guidice6", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) -_addInstrument( "guidice7", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) -_addInstrument( "guidice8", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) -_addInstrument( "guidice9", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) -_addInstrument( "guidice10", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) -_addInstrument( "drum4afrofeet", INST_SIMP, LOW, 'percussions', 0, 0 ,0, 1 ) -_addInstrument( "drum4fingersn", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum4mutecuic", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum4stompbass", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum4tambouri", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum4tr707clap", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum4tr707open", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum4tr808closed", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum4tr808sn", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum4tr909bass", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum4tr909kick", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum4tr909sn", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum5timablesslap", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum5congagraveouvert", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum5timablesaiguslap", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum5congagraveferme", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum5guiroretour", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum5vibraslap", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum5congaaiguouvert", INST_SIMP, MID, 'percussions', 0, 0 ,0, 1 ) -_addInstrument( "drum5quicamedium", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum5quicaaigu", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum5agogograve", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum5bongoaiguouvert", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum5agogoaigu", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "drum5bongograveouvert", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) -_addInstrument( "camera", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) -_addInstrument( "car", INST_TIED, MID, 'concret', .67, 1.05761, .01, 0.7 ) -_addInstrument( "cello", INST_TIED, MID, 'strings', 0.4761, 0.92244375, 0.19125, .75 ) -_addInstrument( "chimes", INST_TIED, MID, 'percussions', 4.104825, 5.644134375, .02, 1 ) -_addInstrument( "crash", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) -_addInstrument( "guit2", INST_TIED, MID, 'strings', 1.186341406, 1.929568266, .2, 0.5 ) -_addInstrument( "plane", INST_SIMP, MID, 'concret', 0, 0, 0, 0.7 ) -_addInstrument( "slap", INST_SIMP, MID, 'concret', 0, 0, 0, 0.7 ) - -try: - ifile = open(PREF_DIR + '/sounds_settings', 'r') - for line in ifile.readlines(): - list = line.split() - _addInstrument(list[0], int(list[1]), int(list[2]), list[3], list[4], float(list[5]), float(list[6]), float(list[7])) -except: - pass - - -DRUM1KIT = { 24 : INSTRUMENTS["drum1kick"], - 26 : INSTRUMENTS["drum1floortom"], - 28 : INSTRUMENTS["drum1tom"], - 30 : INSTRUMENTS["drum1chine"], - 32 : INSTRUMENTS["drum1splash"], - 34 : INSTRUMENTS["drum1crash"], - 36 : INSTRUMENTS["drum1snaresidestick"], - 38 : INSTRUMENTS["drum1snaresidestick"], - 40 : INSTRUMENTS["drum1snare"], - 42 : INSTRUMENTS["drum1ridebell"], - 44 : INSTRUMENTS["drum1hardride"], - 46 : INSTRUMENTS["drum1hatshoulder"], - 48 : INSTRUMENTS["drum1hatpedal"] } - -DRUM2KIT = { 24 : INSTRUMENTS["drum2darbukadoom"], - 26 : INSTRUMENTS["drum2darbukapied"], - 28 : INSTRUMENTS["drum2darbukapiedsoft"], - 30 : INSTRUMENTS["drum2hatflanger"], - 32 : INSTRUMENTS["drum2darbukatak"], - 34 : INSTRUMENTS["drum2darbukatak"], - 36 : INSTRUMENTS["drum2darbukafinger"], - 38 : INSTRUMENTS["drum2darbukaroll"], - 40 : INSTRUMENTS["drum2darbukaslap"], - 42 : INSTRUMENTS["drum2hatpied"], - 44 : INSTRUMENTS["drum2tambourinepied"], - 46 : INSTRUMENTS["drum2hatpied2"], - 48 : INSTRUMENTS["drum2tambourinepiedsoft"] } - -DRUM3KIT = { 24 : INSTRUMENTS["drum3djembelow"], - 26 : INSTRUMENTS["drum3pedalperc"], - 28 : INSTRUMENTS["drum3djembeslap"], - 30 : INSTRUMENTS["drum3tambourinehigh"], - 32 : INSTRUMENTS["drum3tambourinelow"], - 34 : INSTRUMENTS["drum3rainstick"], - 36 : INSTRUMENTS["drum3djembemid"], - 38 : INSTRUMENTS["drum3djembesidestick"], - 40 : INSTRUMENTS["drum3djembestickmid"], - 42 : INSTRUMENTS["drum3cowbell"], - 44 : INSTRUMENTS["drum3cowbelltip"], - 46 : INSTRUMENTS["drum3cup"], - 48 : INSTRUMENTS["drum3metalstand"] } - -DRUM4KIT = { 24 : INSTRUMENTS["drum4afrofeet"], - 26 : INSTRUMENTS["drum4tr909kick"], - 28 : INSTRUMENTS["drum4tr909bass"], - 30 : INSTRUMENTS["drum4stompbass"], - 32 : INSTRUMENTS["drum4tr707open"], - 34 : INSTRUMENTS["drum4mutecuic"], - 36 : INSTRUMENTS["drum4tr808sn"], - 38 : INSTRUMENTS["drum4tr707clap"], - 40 : INSTRUMENTS["drum4tr909sn"], - 42 : INSTRUMENTS["drum4tambouri"], - 44 : INSTRUMENTS["drum4fingersn"], - 46 : INSTRUMENTS["drum4fingersn"], - 48 : INSTRUMENTS["drum4tr808closed"] } - -DRUM5KIT = { 24 : INSTRUMENTS["drum5timablesslap"], - 26 : INSTRUMENTS["drum5timablesaiguslap"], - 28 : INSTRUMENTS["drum5congagraveouvert"], - 30 : INSTRUMENTS["drum5quicamedium"], - 32 : INSTRUMENTS["drum5guiroretour"], - 34 : INSTRUMENTS["drum5vibraslap"], - 36 : INSTRUMENTS["drum5congagraveferme"], - 38 : INSTRUMENTS["drum5quicaaigu"], - 40 : INSTRUMENTS["drum5congaaiguouvert"], - 42 : INSTRUMENTS["drum5agogoaigu"], - 44 : INSTRUMENTS["drum5bongograveouvert"], - 46 : INSTRUMENTS["drum5agogograve"], - 48 : INSTRUMENTS["drum5bongoaiguouvert"] } - -_addInstrument( "drum1kit", 0, 0, "percussions", 0, 0, 0, 1, DRUM1KIT ) -_addInstrument( "drum2kit", 0, 0, "percussions", 0, 0, 0, 1, DRUM2KIT ) -_addInstrument( "drum3kit", 0, 0, "percussions", 0, 0, 0, 1, DRUM3KIT ) -_addInstrument( "drum4kit", 0, 0, "percussions", 0, 0, 0, 1, DRUM4KIT ) -_addInstrument( "drum5kit", 0, 0, "percussions", 0, 0, 0, 1, DRUM5KIT ) - -INSTRUMENTSID = {} -for i in INSTRUMENTS: - INSTRUMENTSID[INSTRUMENTS[i].instrumentId] = INSTRUMENTS[i] - - -#DRUMKITS = ['drum1kit', 'drum2kit', 'drum3kit', 'drum4kit'] -#DRUMSINSTRUMENTSDICT = [DRUM1KIT, DRUM2KIT, DRUM3KIT, DRUM4KIT] - -RECORDABLE_INSTRUMENTS = set( [ "mic1", "mic2", "mic3", "mic4" ] ) -RECORDABLE_INSTRUMENT_CSOUND_IDS = { "mic1" : 7, - "mic2" : 8, - "mic3" : 9, - "mic4" : 10 } - #CSOUND COMMANDS CSOUND_LOAD_INSTRUMENT = 'f%d 0 0 -1 "%s" 0 0 0' CSOUND_MIC_RECORD = 'i5201 0 5 %d' -CSOUND_UNLOAD_TABLES = 'i%d 0 0.1 %d' % (INST_FREE, len(INSTRUMENTS)) +CSOUND_UNLOAD_TABLES = 'i%d 0 0.1 %d' % (INST_FREE, 150) # removed magic number CSOUND_NOTE_OFF = 'i %s.%s .2 0.01 1. 0. 0. 0.5 %d 0 0 0 0' %('%d','%d',INSTRUMENT_TABLE_OFFSET) CSOUND_LOAD_LS_INSTRUMENT = 'f4999 0 0 -1 \"%s\" 0 0 0' CSOUND_PLAY_LS_NOTE = 'i %i 0 -1' CSOUND_STOP_LS_NOTE = 'i 5022 0 0.5' -#CSOUND COMMANDS - DEPRECATED - -LOAD_INSTRUMENT_COMMAND = \ - "perf.InputMessage('f%d 0 0 -1 \"%s\" 0 0 0')\n" -PLAY_NOTE_COMMAND = \ - "perf.InputMessage('i %d.%d %f %f %f %f %f %f %d %f %f %d %f %f %f %f')\n" -#TODO: add the extra three params to COMMAND_MINUS_DELAY, and instrument 5777 in univorc.csd -PLAY_NOTE_COMMAND_MINUS_DELAY = \ - "perf.InputMessage('i 5777 0.0 0.001 %d.%d %s %f %f %f %f %f %d %f %f %d %f')\n" -PLAY_NOTE_OFF_COMMAND = \ - "perf.InputMessage('i %s.%s .2 0.01 1. 0. 0. 0.5 %d 0 0 0 0')\n" \ - % ('%d', '%d', INSTRUMENT_TABLE_OFFSET ) -MIC_RECORDING_COMMAND = \ - "perf.InputMessage('i5201 0 5 %d')\n" -UNLOAD_TABLES_COMMAND = \ - "perf.InputMessage('i%d 0 0.1 %d')\n" % (INST_FREE, len(INSTRUMENTS)) - - - ################# ## GUI CONSTANTS diff --git a/common/Generation/GenerationRythm.py b/common/Generation/GenerationRythm.py index 5e1b31d..583f642 100644 --- a/common/Generation/GenerationRythm.py +++ b/common/Generation/GenerationRythm.py @@ -1,10 +1,13 @@ import Utils import random from math import sqrt +import common.Util.InstrumentDB as InstrumentDB import common.Config as Config from common.Generation.GenerationConstants import GenerationConstants class GenerationRythm: + def __init__(self): + self.instrumentDB = InstrumentDB.getRef() def celluleRythmSequence(self, parameters, barLength, trackId, trackInstrument=None ): rythmSequence = [0, ] @@ -85,7 +88,6 @@ class GenerationRythm: rythmSequence = [] onsetTime = None randomParamScaler = parameters.rythmRegularity[trackId] * 2 + 0.5 -# need radioButton with 0 for random choose and each generator independant whichRandomGenerator = random.randint(0, 4) maximumNumberOfNotes = int( (parameters.density[trackId]) * GenerationConstants.MAX_NOTES_PER_BAR) @@ -133,7 +135,7 @@ class GenerationRythm: upBeatsAppend = upBeats.append - if Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.PUNCH: + if self.instrumentDB.instNamed[ trackInstrument ].instrumentRegister == Config.PUNCH: registerDensity = 0.5 downBeatRecurence = 4 upBeatOffset = Config.TICKS_PER_BEAT / 2 @@ -141,7 +143,7 @@ class GenerationRythm: for downBeat in downBeats: upBeatsAppend( downBeat + upBeatOffset ) - elif Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.LOW: + elif self.instrumentDB.instNamed[ trackInstrument ].instrumentRegister == Config.LOW: registerDensity = 1.5 downBeatRecurence = 4 upBeatOffset = Config.TICKS_PER_BEAT / 2 @@ -149,7 +151,7 @@ class GenerationRythm: for downBeat in downBeats: upBeatsAppend( downBeat + upBeatOffset ) - elif Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.MID: + elif self.instrumentDB.instNamed[ trackInstrument ].instrumentRegister == Config.MID: registerDensity = 1 downBeatRecurence = 1 upBeatOffset = Config.TICKS_PER_BEAT / 4 @@ -157,7 +159,7 @@ class GenerationRythm: for downBeat in downBeats: upBeatsAppend( downBeat + upBeatOffset ) - elif Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.HIGH: + elif self.instrumentDB.instNamed[ trackInstrument ].instrumentRegister == Config.HIGH: registerDensity = 1.5 downBeatRecurence = 1 upBeatOffset = Config.TICKS_PER_BEAT / 4 diff --git a/common/Generation/Generator.py b/common/Generation/Generator.py index 8e92780..ff05462 100755 --- a/common/Generation/Generator.py +++ b/common/Generation/Generator.py @@ -4,12 +4,15 @@ import math import Utils import Drunk +import common.Util.InstrumentDB as InstrumentDB import common.Config as Config from common.Util.CSoundNote import CSoundNote from common.Generation.GenerationConstants import GenerationConstants from common.Generation.GenerationRythm import GenerationRythm from common.Generation.GenerationPitch import GenerationPitch +instrumentDB = InstrumentDB.getRef() + class GenerationParameters: def __init__( self, density = GenerationConstants.DEFAULT_DENSITY, @@ -67,7 +70,7 @@ def generator1( def makeDurationSequence( onsetList, parameters, table_duration, barLength, currentInstrument ): durationSequence = [] - if Config.INSTRUMENTS[currentInstrument].name[0:4] == 'drum': + if instrumentDB.instNamed[currentInstrument].name[0:4] == 'drum': duration = GenerationConstants.DOUBLE_TICK_DUR / 2 durationSequence = [duration] * len(onsetList) return durationSequence @@ -87,7 +90,7 @@ def generator1( trackNotes = trackOfNotes if drumPitch: - currentInstrument = Config.INSTRUMENTS[instrument[pageId][trackId]].kit[drumPitch[0]].name + currentInstrument = instrumentDB.instNamed[instrument[pageId][trackId]].kit[drumPitch[0]] rythmSequence = makeRythm.drumRythmSequence(parameters, currentInstrument, barLength) pitchSequence = makePitch.drumPitchSequence(len(rythmSequence), parameters, drumPitch, table_pitch ) else: @@ -102,7 +105,7 @@ def generator1( rand = random.random append = trackNotes.append pan = GenerationConstants.DEFAULT_PAN - instrument_id = Config.INSTRUMENTS[instrument[pageId][trackId]].instrumentId + instrument_id = instrumentDB.instNamed[instrument[pageId][trackId]].instrumentId for i in numOfNotes: if drumPitch: if ( rand() * fillDrum ) > ( parameters.silence[0] * .5 ): diff --git a/common/Util/Block.py b/common/Util/Block.py index b1395b8..45f942a 100644 --- a/common/Util/Block.py +++ b/common/Util/Block.py @@ -5,6 +5,7 @@ import gtk import random +import common.Util.InstrumentDB as InstrumentDB import common.Config as Config from common.Util.NoteDB import PARAMETER @@ -368,7 +369,7 @@ class Drum(Block): #::: def __init__( self, owner, data ): Block.__init__( self, owner, data ) - + self.instrumentDB = InstrumentDB.getRef() self.type = Drum self.canSubstitute = True @@ -441,7 +442,7 @@ class Drum(Block): if block.type == Loop: return False - if Config.INSTRUMENTSID[block.data["id"]].kit == None: + if self.instrumentDB.instId[block.data["id"]].kit == None: return False if abs( self.x - block.x ) < Block.SNAP and abs( self.y - block.y ) < Block.SNAP: diff --git a/common/Util/CSoundClient.py b/common/Util/CSoundClient.py index e3963cf..c2ca4ff 100644 --- a/common/Util/CSoundClient.py +++ b/common/Util/CSoundClient.py @@ -12,6 +12,7 @@ import common.Config as Config from common.Generation.GenerationConstants import GenerationConstants from common.Util.Clooper.aclient import * from common.Util import NoteDB +import common.Util.InstrumentDB as InstrumentDB _note_template = array.array('f', [0] * 19 ) @@ -50,6 +51,7 @@ class _CSoundClientPlugin: self.periods_per_buffer = 2 global _loop_default _loop_default = self.loopCreate() + self.instrumentDB = InstrumentDB.getRef() def __del__(self): self.connect(False) @@ -75,12 +77,12 @@ class _CSoundClientPlugin: def load_mic_instrument( self, inst ): fileName = Config.SNDS_DIR + '/' + inst - instrumentId = Config.INSTRUMENT_TABLE_OFFSET + Config.INSTRUMENTS[inst].instrumentId + instrumentId = Config.INSTRUMENT_TABLE_OFFSET + self.instrumentDB.instNamed[inst].instrumentId sc_inputMessage(Config.CSOUND_LOAD_INSTRUMENT % (instrumentId, fileName)) def load_synth_instrument( self, inst ): fileName = Config.SNDS_DIR + '/' + inst - instrumentId = Config.INSTRUMENT_TABLE_OFFSET + Config.INSTRUMENTS[inst].instrumentId + instrumentId = Config.INSTRUMENT_TABLE_OFFSET + self.instrumentDB.instNamed[inst].instrumentId sc_inputMessage(Config.CSOUND_LOAD_INSTRUMENT % (instrumentId, fileName)) def load_ls_instrument( self, inst ): @@ -88,12 +90,12 @@ class _CSoundClientPlugin: sc_inputMessage(Config.CSOUND_LOAD_LS_INSTRUMENT % fileName) def load_instruments( self ): - for instrumentSoundFile in Config.INSTRUMENTS.keys(): - if instrumentSoundFile[0:3] == 'mic' or instrumentSoundFile[0:3] == 'lab' or Config.INSTRUMENTS[instrumentSoundFile].category == 'mysounds': + for instrumentSoundFile in self.instrumentDB.instNamed.keys(): + if instrumentSoundFile[0:3] == 'mic' or instrumentSoundFile[0:3] == 'lab' or self.instrumentDB.instNamed[instrumentSoundFile].category == 'mysounds': fileName = Config.SNDS_DIR + '/' + instrumentSoundFile else: fileName = Config.SOUNDS_DIR + "/" + instrumentSoundFile - instrumentId = Config.INSTRUMENT_TABLE_OFFSET + Config.INSTRUMENTS[ instrumentSoundFile ].instrumentId + instrumentId = Config.INSTRUMENT_TABLE_OFFSET + self.instrumentDB.instNamed[ instrumentSoundFile ].instrumentId sc_inputMessage( Config.CSOUND_LOAD_INSTRUMENT % (instrumentId, fileName) ) def connect( self, init = True ): @@ -181,7 +183,7 @@ class _CSoundClientPlugin: if note.cs.mode == 'mini': instrument_id_offset = 0 elif note.cs.mode == 'edit': - if Config.INSTRUMENTSID[note.cs.instrumentId].kit != None: + if self.instrumentDB.instId[note.cs.instrumentId].kit != None: instrument_id_offset = 0 else: instrument_id_offset = 100 @@ -191,8 +193,8 @@ class _CSoundClientPlugin: elif (parameter == NoteDB.PARAMETER.PITCH): if (Config.DEBUG > 2): print 'INFO: updating pitch', (page<<16)+id, value pitch = value - if Config.INSTRUMENTSID[note.cs.instrumentId].kit != None: - instrument = Config.INSTRUMENTSID[note.cs.instrumentId].kit[pitch] + if self.instrumentDB.instId[note.cs.instrumentId].kit != None: + instrument = self.instrumentDB.instId[note.cs.instrumentId].kit[pitch] csoundInstId = instrument.csoundInstrumentId csoundTable = Config.INSTRUMENT_TABLE_OFFSET + instrument.instrumentId if (Config.DEBUG > 2): print 'INFO: updating drum instrument (pitch)', (page<<16)+id, instrument.name, csoundInstId @@ -210,9 +212,9 @@ class _CSoundClientPlugin: sc_loop_updateEvent( loopId, (page<<16)+id, self.DURATION, value, cmd) elif (parameter == NoteDB.PARAMETER.INSTRUMENT): pitch = note.cs.pitch - instrument = Config.INSTRUMENTSID[value] + instrument = self.instrumentDB.instId[value] if instrument.kit != None: - instrument = instrument.kit[pitch] + instrument = self.instrumentDB.instNamed[instrument.kit[pitch]] csoundInstId = instrument.csoundInstrumentId csoundTable = Config.INSTRUMENT_TABLE_OFFSET + instrument.instrumentId loopStart = instrument.loopStart @@ -277,9 +279,9 @@ class _CSoundClientPlugin: tied, instrumentId, mode, instrumentId2 = -1): rval=storage - instrument = Config.INSTRUMENTSID[instrumentId] + instrument = self.instrumentDB.instId[instrumentId] if instrument.kit != None: - instrument = instrument.kit[pitch] + instrument = self.instrumentDB.instNamed[instrument.kit[pitch]] pitch = 1 time_in_ticks = 0 else: @@ -331,7 +333,7 @@ class _CSoundClientPlugin: rval[14]= float(instrument.crossDur) if instrumentId2 != -1: - instrument2 = Config.INSTRUMENTSID[instrumentId2] + instrument2 = self.instrumentDB.instId[instrumentId2] csInstrumentId2 = (instrument2.csoundInstrumentId + 100) * 0.0001 rval[15] = Config.INSTRUMENT_TABLE_OFFSET + instrumentId2 + csInstrumentId2 rval[16] = instrument2.loopStart diff --git a/common/Util/CSoundNote.py b/common/Util/CSoundNote.py index 535084d..a188a62 100644 --- a/common/Util/CSoundNote.py +++ b/common/Util/CSoundNote.py @@ -1,4 +1,5 @@ import common.Config as Config +import common.Util.InstrumentDB as InstrumentDB class CSoundNote : def __init__( self, @@ -8,7 +9,7 @@ class CSoundNote : pan, duration, trackId, - instrumentId = Config.INSTRUMENTS["flute"].instrumentId, + instrumentId = 1, #self.instrumentDB.instNamed["flute"].instrumentId, attack = 0.005, decay = 0.098, reverbSend = 0.1, @@ -18,6 +19,8 @@ class CSoundNote : mode = 'edit', instrumentId2 = -1 ): + self.instrumentDB = InstrumentDB.getRef() + self.onset = onset self.pitch = pitch self.amplitude = amplitude diff --git a/common/Util/InstrumentDB.py b/common/Util/InstrumentDB.py index 900dd86..fd276ae 100644 --- a/common/Util/InstrumentDB.py +++ b/common/Util/InstrumentDB.py @@ -7,21 +7,22 @@ import os class Instrument: def __init__(self, id): - self.id = id + self.instrumentId = id # build an Instrument instance from argument list def loadFromArgs( self, name, csoundInstrumentId, register, loopStart, - loopEnd, crossDur, ampScale, wav, img, labels ): + loopEnd, crossDur, ampScale, kit, wav, img, category ): self.name = name self.csoundInstrumentId = csoundInstrumentId - self.register = register + self.instrumentRegister = register self.loopStart = loopStart self.loopEnd = loopEnd self.crossDur = crossDur self.ampScale = ampScale + self.kit = kit self.wav = wav self.img = img - self.labels = labels + self.category = category # build an Instrument instance by parsing a file def loadFromPath(self, path ): @@ -36,9 +37,10 @@ class Instrument: self.loopEnd = float( f.readline()) self.crossDur = float( f.readline()) self.ampScale = float( f.readline()) + self.kit = None self.wav = f.readline() self.img = f.readline() - self.labels = f.readline().split() + self.category = f.readline().split() f.close() class InstrumentDB: @@ -48,22 +50,21 @@ class InstrumentDB: self.labelSet = {'All':set([])} # -> all instruments labelled by self.inst = [] # all instruments self.instNamed = {} # -> instrument with that name - self.kit = [] # all kits. kits are lists of 13 instruments - self.kitNamed = {} # -> kit with that name + self.instId = {} # -> instrument # TEMP? add instrument from args def addInstrumentFromArgs( self, name, csoundInstrumentId, register, loopStart, - loopEnd, crossDur, ampScale, wav, img, labels ): + loopEnd, crossDur, ampScale, kit, wav, img, category ): i = Instrument(len(self.inst)) self.inst += [ i ] - i.loadFromArgs( name, csoundInstrumentId, register, loopStart, loopEnd, crossDur, ampScale, wav, img, labels ) - #print 'labelSet... ', self.labelSet - self.labelSet['All'].add(i) - for l in i.labels: - if l not in self.labelSet: - self.labelSet[l] = set([]) - self.labelSet[l].add( i ) + i.loadFromArgs( name, csoundInstrumentId, register, loopStart, loopEnd, crossDur, ampScale, kit, wav, img, category ) + self.instNamed[ i.name ] = i + self.instId[i.instrumentId] = i + self.labelSet['All'].add(i) + if not self.labelSet.has_key(category): + self.labelSet[category] = set([]) + self.labelSet[category].add( i ) # add an instrument to the DB by reading from an instrument definition file def addInstrument( self, path ): @@ -71,23 +72,12 @@ class InstrumentDB: self.inst += [ i ] i.loadFromPath( path ) self.instNamed[ i.name ] = i + self.instId[self.instNamed[i].instrumentId] = i #print 'labelSet... ', self.labelSet self.labelSet['All'].add(i) - for l in i.labels: - if l not in self.labelSet: - self.labelSet[l] = set([]) - self.labelSet[l].add( i ) - - # add a kit by reading from a kit definition file - def addKit( self, path ): - strlist = file(path, 'r').readline().split() - if len(strlist) != 14: - raise 'kit length != 13' - for str in strlist[1:]: - if str not in self.inst_named: - raise 'invalid instrument' - kit = [ self.instNamed[name] for name in strlist ] - self.kit += [ kit ] + if not self.labelSet.has_key(category): + self.labelSet[category] = set([]) + self.labelSet[category].add( i ) # try to load each file in a given folder as an instrument def. file def scanInstrumentDir( self, path ): @@ -98,15 +88,6 @@ class InstrumentDB: except : print 'ERROR: scanning instrument path %s: file %s invalid' % (path, fpath) - # try to load each file in a given folder as a kit def. file - def scanKitDir( self, path ): - dirlist = os.listdir( path ) - for fpath in dirlist: - try : - self.addKit( fpath ) - except : - print 'ERROR: scanning kit path %s: file %s invalid' % (path, fpath) - def getLabels( self ): return self.labelSet.keys() diff --git a/common/Util/InstrumentPanel.py b/common/Util/InstrumentPanel.py index 8cac210..fc933b9 100644 --- a/common/Util/InstrumentPanel.py +++ b/common/Util/InstrumentPanel.py @@ -6,6 +6,7 @@ import gtk import time +import common.Util.InstrumentDB as InstrumentDB import common.Config as Config from common.Util.ThemeWidgets import * Tooltips = Config.Tooltips @@ -14,6 +15,7 @@ class InstrumentPanel( gtk.EventBox ): def __init__(self,setInstrument = None, playInstrument = None, enterMode = False, micRec = None, synthRec = None, rowLen = 8, _instDic = None, force_load = True ): gtk.EventBox.__init__(self) + self.instrumentDB = InstrumentDB.getRef() self.setInstrument = setInstrument self.playInstrument = playInstrument self.micRec = micRec @@ -116,10 +118,10 @@ class InstrumentPanel( gtk.EventBox ): if timeout >= 0 and time.time() > timeout: return False if loadStage[1] == 1: - keys = Config.INSTRUMENTS.keys() + keys = self.instrumentDB.instNamed.keys() for i in range(loadStage[2], len(keys)): key = keys[i] - instrument = Config.INSTRUMENTS[key] + instrument = self.instrumentDB.instNamed[key] if key[0:4] != 'drum' and key[0:4] != 'guid' and key[0:3] != 'mic' and key[0:3] != 'lab': self.instrumentList["all"].append( key ) if key[0:4] != 'drum' and key[0:4] != 'guid' and key[0:3] != 'mic' and key[0:3] != 'lab': @@ -333,9 +335,9 @@ class DrumPanel( gtk.EventBox ): self.setDrum = setDrum self.instrumentList = [] - keys = Config.INSTRUMENTS.keys() - for key in Config.INSTRUMENTS.keys(): - if Config.INSTRUMENTS[key].category == "kit": + keys = self.instrumentDB.instNamed.keys() + for key in self.instrumentDB.instNamed.keys(): + if self.instrumentDB.instNamed[key].category == "kit": self.instrumentList.append( key ) self.instrumentList.sort() self.drawDrums() diff --git a/common/Util/Instruments.py b/common/Util/Instruments.py new file mode 100644 index 0000000..9382d9e --- /dev/null +++ b/common/Util/Instruments.py @@ -0,0 +1,240 @@ +import common.Config as Config +import common.Util.InstrumentDB as InstrumentDB + +LOW = Config.LOW +MID = Config.MID +HIGH = Config.HIGH +PUNCH = Config.PUNCH + +INSTRUMENT_TABLE_OFFSET = Config.INSTRUMENT_TABLE_OFFSET +INST_FREE = Config.INST_FREE +INST_TIED = Config.INST_TIED +INST_SIMP = Config.INST_SIMP +INST_PERC = Config.INST_PERC + +instrumentDB = InstrumentDB.getRef() + + +def _addInstrument( name, csoundInstrumentId, instrumentRegister, category, loopStart, loopEnd, crossDur, ampScale = 1, kit = None ): + instrumentDB.addInstrumentFromArgs( name, csoundInstrumentId, instrumentRegister, loopStart, loopEnd, crossDur, ampScale, kit, name, Config.LIB_DIR+"/Images/"+name+".png", category ) + + +_addInstrument( "mic1", INST_TIED, MID, 'mysounds', .01, 1.99, .01, 1 ) +_addInstrument( "mic2", INST_TIED, MID, 'mysounds', .01, 1.99, .01, 1 ) +_addInstrument( "mic3", INST_TIED, MID, 'mysounds', .01, 1.99, .01, 1 ) +_addInstrument( "mic4", INST_TIED, MID, 'mysounds', .01, 1.99, .01, 1 ) +_addInstrument( "lab1", INST_SIMP, MID, 'mysounds', 0, 0, 0, 1 ) +_addInstrument( "lab2", INST_SIMP, MID, 'mysounds', 0, 0, 0, 1 ) +_addInstrument( "lab3", INST_SIMP, MID, 'mysounds', 0, 0, 0, 1 ) +_addInstrument( "lab4", INST_SIMP, MID, 'mysounds', 0, 0, 0, 1 ) +_addInstrument( "lab5", INST_SIMP, MID, 'mysounds', 0, 0, 0, 1 ) +_addInstrument( "lab6", INST_SIMP, MID, 'mysounds', 0, 0, 0, 1 ) +_addInstrument( "ounk", INST_SIMP, MID, 'animals', 0, 0, 0, 1 ) +_addInstrument( "gam", INST_TIED, HIGH, 'percussions', .69388, .7536, .02922, 1 ) +_addInstrument( "guit", INST_TIED, MID, 'strings', .08592, .75126, .33571, 1.3 ) +_addInstrument( "koto", INST_TIED, HIGH, 'strings', .56523, .70075, .05954, 1 ) +_addInstrument( "clarinette", INST_TIED, MID, 'winds', 1.635276375, 2.72956523438, .2, 0.6 ) +_addInstrument( "flute", INST_TIED, MID, 'winds', .47169, .53693, .02481, 1 ) +_addInstrument( "drum1hatpedal", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum1hatshoulder", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum1hardride", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum1ridebell", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum1snare", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum1snaresidestick", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum1crash", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum1splash", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum1tom", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum1floortom", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1) +_addInstrument( "drum1chine", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum1kick", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "piano", INST_TIED, MID, 'keyboard', 0.8883, 1.420524, .13575, 1 ) +_addInstrument( "dog", INST_SIMP, MID, 'animals', 0, 0, 0, 1 ) +_addInstrument( "duck", INST_SIMP, MID, 'animals', 0, 0, 0, 1 ) +_addInstrument( "drum2darbukadoom", INST_SIMP, LOW, 'percussions', 0, 0 ,0, 1 ) +_addInstrument( "drum2darbukapied", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum2darbukapiedsoft", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum2hatflanger", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum2darbukatak", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum2darbukafinger", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum2darbukaroll", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum2darbukaslap", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum2hatpied", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum2tambourinepied", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum2hatpied2", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum2tambourinepiedsoft", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum3cowbell", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum3cowbelltip", INST_SIMP, MID, 'percussions', 0, 0, 0, 1) +_addInstrument( "drum3cup", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum3djembelow", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum3djembemid", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum3djembesidestick", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum3djembeslap", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum3djembestickmid", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum3metalstand", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum3pedalperc", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum3rainstick", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum3tambourinehigh", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum3tambourinelow", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "harmonica", INST_TIED, MID, 'winds', .1531, .19188, .01792, 1 ) +_addInstrument( "alarm", INST_TIED, MID, 'concret', 1.37555859375, 2.0286015625, .0675, 0.5 ) +_addInstrument( "bird", INST_TIED, MID, 'animals', .1, 1, .05, 1 ) +_addInstrument( "cat", INST_SIMP, MID, 'animals', 0, 0, 0, 1 ) +_addInstrument( "duck2", INST_SIMP, MID, 'animals', 0, 0, 0, 1 ) +_addInstrument( "bottle", INST_TIED, MID, 'concret', .20532, .41064, .05292, 1 ) +_addInstrument( "clang", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) +_addInstrument( "ow", INST_SIMP, MID, 'people', 0, 0, 0, 1 ) +_addInstrument( "sheep", INST_SIMP, MID, 'animals', 0, 0, 0, 1 ) +_addInstrument( "water", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) +_addInstrument( "zap", INST_TIED, MID, 'keyboard', .299, .7323, .09895, 1 ) +_addInstrument( "trumpet", INST_TIED, MID, 'winds', .91195, 1.652909375, .05375, 0.5) +_addInstrument( "bubbles", INST_TIED, MID, 'concret', 0.02, 1.177, 0.02, 1) +_addInstrument( "marimba", INST_TIED, MID, 'percussions', .18883789, .343623047, .07625, 0.5) +_addInstrument( "triangle", INST_TIED, MID, 'percussions', 2.27261836, 3.2965453, .2, 0.6) +_addInstrument( "laugh", INST_SIMP, MID, 'people', 0, 0, 0, 1 ) +_addInstrument( "voix", INST_TIED, MID, 'people', .89608, .96092, .02343, 1 ) +_addInstrument( "cling", INST_TIED, MID, 'keyboard', .09096, .7878, .18026, 1 ) +_addInstrument( "byke", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) +_addInstrument( "door", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) +_addInstrument( "basse", INST_TIED, MID, 'strings', 0.50470875, 0.833315, 0.09375, 1 ) +_addInstrument( "acguit", INST_TIED, MID, 'strings', 1.4037, 1.84235625, 0.2, 0.8 ) +_addInstrument( "diceinst", INST_SIMP, MID, 'concret', 0, 0, 0, 1.3 ) +_addInstrument( "didjeridu", INST_TIED, LOW, 'winds', .55669, 1.73704, .09178, 2 ) +_addInstrument( "harmonium", INST_TIED, MID, 'keyboard', .242032, .898165625, .2, 0.5 ) +_addInstrument( "horse", INST_SIMP, MID, 'animals', 0, 0, 0, 1 ) +_addInstrument( "kalimba", INST_TIED, MID, 'percussions', .20751, .30161, .04658, 1.3 ) +_addInstrument( "mando", INST_TIED, MID, 'strings', 0.507107031, 0.934144531, 0.2, 0.5 ) +_addInstrument( "ocarina", INST_TIED, MID, 'winds', .06612, .19033, .01776, 1 ) +_addInstrument( "rhodes", INST_TIED, MID, 'keyboard', 0.58100625, 0.821625, 0.067, 1 ) +_addInstrument( "saxo", INST_TIED, MID, 'winds', 1.161051953, 3.001209765, .05, 0.5 ) +_addInstrument( "shenai", INST_TIED, MID, 'winds', .29003, .33072, .00634, 0.7 ) +_addInstrument( "sitar", INST_TIED, MID, 'strings', 1.1361625, 1.575134375, .183, 0.4 ) +_addInstrument( "tuba", INST_TIED, LOW, 'winds', .51063, .58384, .035, 1 ) +_addInstrument( "violin", INST_TIED, MID, 'strings', .105, .30656, .028, 1 ) +_addInstrument( "guidice1", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) +_addInstrument( "guidice2", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) +_addInstrument( "guidice3", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) +_addInstrument( "guidice4", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) +_addInstrument( "guidice5", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) +_addInstrument( "guidice6", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) +_addInstrument( "guidice7", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) +_addInstrument( "guidice8", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) +_addInstrument( "guidice9", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) +_addInstrument( "guidice10", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) +_addInstrument( "drum4afrofeet", INST_SIMP, LOW, 'percussions', 0, 0 ,0, 1 ) +_addInstrument( "drum4fingersn", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum4mutecuic", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum4stompbass", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum4tambouri", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum4tr707clap", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum4tr707open", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum4tr808closed", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum4tr808sn", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum4tr909bass", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum4tr909kick", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum4tr909sn", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum5timablesslap", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum5congagraveouvert", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum5timablesaiguslap", INST_SIMP, LOW, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum5congagraveferme", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum5guiroretour", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum5vibraslap", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum5congaaiguouvert", INST_SIMP, MID, 'percussions', 0, 0 ,0, 1 ) +_addInstrument( "drum5quicamedium", INST_SIMP, PUNCH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum5quicaaigu", INST_SIMP, MID, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum5agogograve", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum5bongoaiguouvert", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum5agogoaigu", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "drum5bongograveouvert", INST_SIMP, HIGH, 'percussions', 0, 0, 0, 1 ) +_addInstrument( "camera", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) +_addInstrument( "car", INST_TIED, MID, 'concret', .67, 1.05761, .01, 0.7 ) +_addInstrument( "cello", INST_TIED, MID, 'strings', 0.4761, 0.92244375, 0.19125, .75 ) +_addInstrument( "chimes", INST_TIED, MID, 'percussions', 4.104825, 5.644134375, .02, 1 ) +_addInstrument( "crash", INST_SIMP, MID, 'concret', 0, 0, 0, 1 ) +_addInstrument( "guit2", INST_TIED, MID, 'strings', 1.186341406, 1.929568266, .2, 0.5 ) +_addInstrument( "plane", INST_SIMP, MID, 'concret', 0, 0, 0, 0.7 ) +_addInstrument( "slap", INST_SIMP, MID, 'concret', 0, 0, 0, 0.7 ) + +try: + ifile = open(PREF_DIR + '/sounds_settings', 'r') + for line in ifile.readlines(): + list = line.split() + _addInstrument(list[0], int(list[1]), int(list[2]), list[3], list[4], float(list[5]), float(list[6]), float(list[7]), float(list[8])) +except: + pass + + +DRUM1KIT = { 24 : "drum1kick", + 26 : "drum1floortom", + 28 : "drum1tom", + 30 : "drum1chine", + 32 : "drum1splash", + 34 : "drum1crash", + 36 : "drum1snaresidestick", + 38 : "drum1snaresidestick", + 40 : "drum1snare", + 42 : "drum1ridebell", + 44 : "drum1hardride", + 46 : "drum1hatshoulder", + 48 : "drum1hatpedal" } + +DRUM2KIT = { 24 : "drum2darbukadoom", + 26 : "drum2darbukapied", + 28 : "drum2darbukapiedsoft", + 30 : "drum2hatflanger", + 32 : "drum2darbukatak", + 34 : "drum2darbukatak", + 36 : "drum2darbukafinger", + 38 : "drum2darbukaroll", + 40 : "drum2darbukaslap", + 42 : "drum2hatpied", + 44 : "drum2tambourinepied", + 46 : "drum2hatpied2", + 48 : "drum2tambourinepiedsoft" } + +DRUM3KIT = { 24 : "drum3djembelow", + 26 : "drum3pedalperc", + 28 : "drum3djembeslap", + 30 : "drum3tambourinehigh", + 32 : "drum3tambourinelow", + 34 : "drum3rainstick", + 36 : "drum3djembemid", + 38 : "drum3djembesidestick", + 40 : "drum3djembestickmid", + 42 : "drum3cowbell", + 44 : "drum3cowbelltip", + 46 : "drum3cup", + 48 : "drum3metalstand" } + +DRUM4KIT = { 24 : "drum4afrofeet", + 26 : "drum4tr909kick", + 28 : "drum4tr909bass", + 30 : "drum4stompbass", + 32 : "drum4tr707open", + 34 : "drum4mutecuic", + 36 : "drum4tr808sn", + 38 : "drum4tr707clap", + 40 : "drum4tr909sn", + 42 : "drum4tambouri", + 44 : "drum4fingersn", + 46 : "drum4fingersn", + 48 : "drum4tr808closed" } + +DRUM5KIT = { 24 : "drum5timablesslap", + 26 : "drum5timablesaiguslap", + 28 : "drum5congagraveouvert", + 30 : "drum5quicamedium", + 32 : "drum5guiroretour", + 34 : "drum5vibraslap", + 36 : "drum5congagraveferme", + 38 : "drum5quicaaigu", + 40 : "drum5congaaiguouvert", + 42 : "drum5agogoaigu", + 44 : "drum5bongograveouvert", + 46 : "drum5agogograve", + 48 : "drum5bongoaiguouvert" } + +_addInstrument( "drum1kit", 0, 0, "percussions", 0, 0, 0, 1, DRUM1KIT ) +_addInstrument( "drum2kit", 0, 0, "percussions", 0, 0, 0, 1, DRUM2KIT ) +_addInstrument( "drum3kit", 0, 0, "percussions", 0, 0, 0, 1, DRUM3KIT ) +_addInstrument( "drum4kit", 0, 0, "percussions", 0, 0, 0, 1, DRUM4KIT ) +_addInstrument( "drum5kit", 0, 0, "percussions", 0, 0, 0, 1, DRUM5KIT ) diff --git a/common/Util/NoteDB.py b/common/Util/NoteDB.py index e62ca32..646f8d8 100644 --- a/common/Util/NoteDB.py +++ b/common/Util/NoteDB.py @@ -1,4 +1,4 @@ - +import common.Util.InstrumentDB as InstrumentDB import common.Config as Config class PARAMETER: @@ -35,13 +35,14 @@ class Note: class Page: def __init__( self, beats, color = 0, instruments = False, local = True ): # , tempo, insruments, color = 0 ): + self.instrumentDB = InstrumentDB.getRef() self.beats = beats self.ticks = beats*Config.TICKS_PER_BEAT self.color = color if not instruments: - self.instruments = [ Config.INSTRUMENTS["kalimba"].instrumentId for i in range(Config.NUMBER_OF_TRACKS-1) ] + [ Config.INSTRUMENTS["drum1kit"].instrumentId ] + self.instruments = [ self.instrumentDB.instNamed["kalimba"].instrumentId for i in range(Config.NUMBER_OF_TRACKS-1) ] + [ self.instrumentDB.instNamed["drum1kit"].instrumentId ] else: self.instruments = instruments[:] @@ -85,6 +86,7 @@ class NoteListener: class NoteDB: def __init__( self ): + self.instrumentDB = InstrumentDB.getRef() self.noteD = {} # bins containing all the notes by page, track, and id # structure self.noteD[pageId][trackIndex][noteId] @@ -283,7 +285,7 @@ class NoteDB: for page in pages: list = [] for track in range(Config.NUMBER_OF_TRACKS): - list.append(Config.INSTRUMENTSID[self.pages[page].instruments[track]].name) + list.append(self.instrumentDB.instId[self.pages[page].instruments[track]].name) dict[page] = list[:] return dict -- cgit v0.9.1