From 3e9a586f404b70cda362cf888653de9c940fd849 Mon Sep 17 00:00:00 2001 From: Oli Date: Fri, 19 Oct 2007 08:08:02 +0000 Subject: switch to instrumentDB --- (limited to 'common/Generation') 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 ): -- cgit v0.9.1