From 75dcef4ab8b11d78a4547e8027ae0905a47dbf97 Mon Sep 17 00:00:00 2001 From: Nat Date: Wed, 19 Sep 2007 17:31:08 +0000 Subject: Instrumentpanel test in edit --- (limited to 'TamTamMini.activity') diff --git a/TamTamMini.activity/Config.py b/TamTamMini.activity/Config.py new file mode 100644 index 0000000..7bbf724 --- /dev/null +++ b/TamTamMini.activity/Config.py @@ -0,0 +1,596 @@ +# -*- 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 + +SugarMode = True + +if os.path.isfile("DEBUG"): + f = open("DEBUG") + l = f.read(10) + f.close() + if len(l): DEBUG = int( l ) + else: DEBUG = 99 +else: + DEBUG = 0 +print "Debug Level %d" % (DEBUG) + + +TAM_TAM_ROOT = get_bundle_path() +print 'INFO: loaded TAMTAM_ROOT=%s' % TAM_TAM_ROOT + + +#PATHS +if os.path.isdir('/usr/share/activities/TamTamEdit.activity/Resources/Sounds'): + SOUNDS_DIR = "/usr/share/activities/TamTamEdit.activity/Resources/Sounds" +else: + SOUNDS_DIR = TAM_TAM_ROOT + "/common/Resources/Sounds" +FILES_DIR = TAM_TAM_ROOT + "/common/Resources" +TUNE_DIR='/' +SYNTH_DIR='/' +if SugarMode == True: + PREF_DIR = env.get_profile_path() + '/tamtam' + TUNE_DIR=env.get_profile_path() + '/tamtam/tunes' + SYNTH_DIR=env.get_profile_path() + '/tamtam/synthlab' + SNDS_DIR=env.get_profile_path() + '/tamtam/snds' + SCRATCH_DIR = PREF_DIR + "/.scratch/" +else: + PREF_DIR = os.getenv('HOME') + '/.tamtam' + TUNE_DIR= os.getenv('HOME') + '/.tamtam/tunes' + SYNTH_DIR= os.getenv('HOME') + '/.tamtam/synthlab' + SNDS_DIR= os.getenv('HOME') + '/.tamtam/snds' + SCRATCH_DIR = PREF_DIR + "/.scratch/" + +#PLUGIN +PLUGIN_DEBUG = PREF_DIR + "/clooper.log" +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, soundClass, category, loopStart, loopEnd, crossDur, kit = None ): + self.name = name + self.instrumentId = instrumentId + self.csoundInstrumentId = csoundInstrumentId + self.instrumentRegister = instrumentRegister + self.soundClass = soundClass + self.category = category + self.loopStart = loopStart + self.loopEnd = loopEnd + self.crossDur = crossDur + self.kit = kit + #print (self.name, self.instrumentId, self.csoundInstrumentId, self.instrumentRegister, self.soundClass, self.category, self.loopStart, self.loopEnd, self.crossDur) + +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 +INST_SIMP = 5011 +INST_PERC = 5021 + +CATEGORIES = ['all','animals','concret','keyboard','people','percussions','strings','winds', 'mysounds'] + +instrumentDB = InstrumentDB.getRef() + +_nextInstrumentId = [0] +INSTRUMENTS = {} +def _addInstrument( name, csoundInstrumentId, instrumentRegister, soundClass, category, loopStart, loopEnd, crossDur, 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, soundClass, category, loopStart, loopEnd, crossDur, kit ) + instrumentDB.addInstrumentFromArgs( name, name, instrumentRegister, loopStart, loopEnd, crossDur, name, FILES_DIR+"/Images/"+name+".png", [ category ] ) + _nextInstrumentId[0] += 1 + + +_addInstrument( "mic1", INST_TIED, MID, 'melo', 'mic', .01, 1.99, .01 ) +_addInstrument( "mic2", INST_TIED, MID, 'melo', 'mic', .01, 1.99, .01 ) +_addInstrument( "mic3", INST_TIED, MID, 'melo', 'mic', .01, 1.99, .01 ) +_addInstrument( "mic4", INST_TIED, MID, 'melo', 'mic', .01, 1.99, .01 ) +_addInstrument( "lab1", INST_SIMP, MID, 'melo', 'lab', 0, 0, 0 ) +_addInstrument( "lab2", INST_SIMP, MID, 'melo', 'lab', 0, 0, 0 ) +_addInstrument( "lab3", INST_SIMP, MID, 'melo', 'lab', 0, 0, 0 ) +_addInstrument( "lab4", INST_SIMP, MID, 'melo', 'lab', 0, 0, 0 ) +_addInstrument( "lab5", INST_SIMP, MID, 'melo', 'lab', 0, 0, 0 ) +_addInstrument( "lab6", INST_SIMP, MID, 'melo', 'lab', 0, 0, 0 ) +_addInstrument( "ounk", INST_SIMP, MID, 'melo', 'animals', 0, 0, 0 ) +_addInstrument( "gam", INST_TIED, HIGH, 'melo', 'percussions', .69388, .7536, .02922 ) +_addInstrument( "guit", INST_TIED, MID, 'melo', 'strings', .08592, .75126, .33571 ) +_addInstrument( "koto", INST_TIED, HIGH, 'melo', 'strings', .56523, .70075, .05954 ) +_addInstrument( "clarinette", INST_TIED, MID, 'melo', 'winds', .57905, .73319, .04934 ) +_addInstrument( "flute", INST_TIED, MID, 'melo', 'winds', .47169, .53693, .02481 ) +_addInstrument( "drum1hatpedal", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum1hatshoulder", INST_SIMP, HIGH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum1hardride", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum1ridebell", INST_SIMP, HIGH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum1snare", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum1snaresidestick", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum1crash", INST_SIMP, PUNCH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum1splash", INST_SIMP, PUNCH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum1tom", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum1floortom", INST_SIMP, LOW, 'drum', 'drum', 0, 0, 0) +_addInstrument( "drum1chine", INST_SIMP, PUNCH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum1kick", INST_SIMP, LOW, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "piano", INST_TIED, MID, 'melo', 'keyboard', 0.8883, 1.420524, .13575 ) +_addInstrument( "dog", INST_SIMP, MID, 'melo', 'animals', 0, 0, 0 ) +_addInstrument( "duck", INST_SIMP, MID, 'melo', 'animals', 0, 0, 0 ) +_addInstrument( "drum2darbukadoom", INST_SIMP, LOW, 'drum', 'drum', 0, 0 ,0 ) +_addInstrument( "drum2darbukapied", INST_SIMP, LOW, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum2darbukapiedsoft", INST_SIMP, LOW, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum2hatflanger", INST_SIMP, PUNCH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum2darbukatak", INST_SIMP, PUNCH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum2darbukafinger", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum2darbukaroll", INST_SIMP, HIGH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum2darbukaslap", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum2hatpied", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum2tambourinepied", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum2hatpied2", INST_SIMP, HIGH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum2tambourinepiedsoft", INST_SIMP, HIGH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum3cowbell", INST_SIMP, HIGH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum3cowbelltip", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0) +_addInstrument( "drum3cup", INST_SIMP, HIGH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum3djembelow", INST_SIMP, LOW, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum3djembemid", INST_SIMP, HIGH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum3djembesidestick", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum3djembeslap", INST_SIMP, LOW, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum3djembestickmid", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum3metalstand", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum3pedalperc", INST_SIMP, LOW, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum3rainstick", INST_SIMP, PUNCH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum3tambourinehigh", INST_SIMP, PUNCH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum3tambourinelow", INST_SIMP, PUNCH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "harmonica", INST_TIED, MID, 'melo', 'winds', .1531, .19188, .01792 ) +_addInstrument( "alarm", INST_TIED, MID, 'melo', 'concret', .02, .19133, .01 ) +_addInstrument( "bird", INST_TIED, MID, 'melo', 'animals', .1, 1, .05 ) +_addInstrument( "cat", INST_SIMP, MID, 'melo', 'animals', 0, 0, 0 ) +_addInstrument( "duck2", INST_SIMP, MID, 'melo', 'animals', 0, 0, 0 ) +_addInstrument( "bottle", INST_TIED, MID, 'melo', 'concret', .20532, .41064, .05292 ) +_addInstrument( "clang", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "ow", INST_SIMP, MID, 'melo', 'people', 0, 0, 0 ) +_addInstrument( "sheep", INST_SIMP, MID, 'melo', 'animals', 0, 0, 0 ) +_addInstrument( "water", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "zap", INST_TIED, MID, 'melo', 'keyboard', .299, .7323, .09895 ) +_addInstrument( "trumpet", INST_TIED, MID, 'melo', 'winds', .39934, .45537, .02729) +_addInstrument( "bubbles", INST_TIED, MID, "melo", 'concret', 0.02, 1.177, 0.02) +_addInstrument( "marimba", INST_TIED, MID, "melo", 'percussions', .26545, .33098, .03087) +_addInstrument( "triangle", INST_TIED, MID, "melo", 'percussions', 1.21002, 1.31805, .01268) +_addInstrument( "laugh", INST_SIMP, MID, 'melo', 'people', 0, 0, 0 ) +_addInstrument( "voix", INST_TIED, MID, 'melo', 'people', .89608, .96092, .02343 ) +_addInstrument( "cling", INST_TIED, MID, 'melo', 'keyboard', .09096, .7878, .18026 ) +_addInstrument( "byke", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "door", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "basse", INST_TIED, MID, 'melo', 'strings', 0.50470875, 0.833315, 0.09375 ) +_addInstrument( "acguit", INST_TIED, MID, 'melo', 'strings', 0.5123225, 0.7491675, 0.08475 ) +_addInstrument( "diceinst", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "didjeridu", INST_TIED, LOW, 'melo', 'winds', .55669, 1.73704, .09178 ) +_addInstrument( "harmonium", INST_TIED, MID, 'melo', 'keyboard', .04674, .41073, .18384 ) +_addInstrument( "horse", INST_SIMP, MID, 'melo', 'animals', 0, 0, 0 ) +_addInstrument( "kalimba", INST_TIED, MID, 'melo', 'percussions', .20751, .30161, .04658 ) +_addInstrument( "mando", INST_TIED, MID, 'melo', 'strings', 0.316548, 0.532008, 0.02875 ) +_addInstrument( "ocarina", INST_TIED, MID, 'melo', 'winds', .06612, .19033, .01776 ) +_addInstrument( "rhodes", INST_TIED, MID, 'melo', 'keyboard', 0.58100625, 0.821625, 0.067 ) +_addInstrument( "saxo", INST_TIED, MID, 'melo', 'winds', .53722, .6583, .05264 ) +_addInstrument( "shenai", INST_TIED, MID, 'melo', 'winds', .29003, .33072, .00634 ) +_addInstrument( "sitar", INST_TIED, MID, 'melo', 'strings', .63187, .67882, .01654 ) +_addInstrument( "tuba", INST_TIED, LOW, 'melo', 'winds', .51063, .58384, .035 ) +_addInstrument( "violin", INST_TIED, MID, 'melo', 'strings', .105, .30656, .028 ) +_addInstrument( "guidice1", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "guidice2", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "guidice3", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "guidice4", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "guidice5", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "guidice6", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "guidice7", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "guidice8", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "guidice9", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "guidice10", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "drum4afrofeet", INST_SIMP, LOW, 'drum', 'drum', 0, 0 ,0 ) +_addInstrument( "drum4fingersn", INST_SIMP, HIGH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum4mutecuic", INST_SIMP, PUNCH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum4stompbass", INST_SIMP, PUNCH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum4tambouri", INST_SIMP, HIGH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum4tr707clap", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum4tr707open", INST_SIMP, PUNCH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum4tr808closed", INST_SIMP, HIGH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum4tr808sn", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum4tr909bass", INST_SIMP, LOW, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum4tr909kick", INST_SIMP, LOW, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum4tr909sn", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum5timablesslap", INST_SIMP, LOW, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum5congagraveouvert", INST_SIMP, LOW, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum5timablesaiguslap", INST_SIMP, LOW, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum5congagraveferme", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum5guiroretour", INST_SIMP, PUNCH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum5vibraslap", INST_SIMP, PUNCH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum5congaaiguouvert", INST_SIMP, MID, 'drum', 'drum', 0, 0 ,0 ) +_addInstrument( "drum5quicamedium", INST_SIMP, PUNCH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum5quicaaigu", INST_SIMP, MID, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum5agogograve", INST_SIMP, HIGH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum5bongoaiguouvert", INST_SIMP, HIGH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum5agogoaigu", INST_SIMP, HIGH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "drum5bongograveouvert", INST_SIMP, HIGH, 'drum', 'drum', 0, 0, 0 ) +_addInstrument( "camera", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "car", INST_TIED, MID, 'melo', 'concret', .67, 1.05761, .01 ) +#_addInstrument( "cello", INST_TIED, MID, 'melo', 'strings', .194, .7211, .017 ) +_addInstrument( "chimes", INST_TIED, MID, 'melo', 'percussions', .09, 2.97633, .01 ) +_addInstrument( "crash", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "guit2", INST_TIED, MID, 'melo', 'strings', .33, 1.1583, .02 ) +_addInstrument( "plane", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) +_addInstrument( "slap", INST_SIMP, MID, 'melo', 'concret', 0, 0, 0 ) + +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, 0, "kit", 0, 0, 0, DRUM1KIT ) +_addInstrument( "drum2kit", 0, 0, 0, "kit", 0, 0, 0, DRUM2KIT ) +_addInstrument( "drum3kit", 0, 0, 0, "kit", 0, 0, 0, DRUM3KIT ) +_addInstrument( "drum4kit", 0, 0, 0, "kit", 0, 0, 0, DRUM4KIT ) +_addInstrument( "drum5kit", 0, 0, 0, "kit", 0, 0, 0, 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_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 +################# + +LANGUAGE = 'En' +IMAGE_ROOT = TAM_TAM_ROOT + '/common/Resources/Images/' +MAIN_WINDOW_PADDING = 5 + +BG_COLOR = '#404040' +FG_COLOR = '#818286' + +NOTE_HEIGHT = 9 # pixels +NOTE_IMAGE_PADDING = 6 +NOTE_IMAGE_PADDING_MUL2 = NOTE_IMAGE_PADDING*2 +NOTE_IMAGE_TAIL = 1059 +NOTE_IMAGE_ENDLENGTH = 12 +HIT_HEIGHT = 13 # pixels +HIT_IMAGE_PADDING = 6 +HIT_IMAGE_PADDING_MUL2 = HIT_IMAGE_PADDING*2 +TRACK_SPACING = 4 +TRACK_SPACING_DIV2 = TRACK_SPACING//2 +TRACK_COLORS = [ ( "#00290B", "#00E847" ), \ + ( "#3F0200", "#E72500" ), \ + ( "#002642", "#0090EA" ), \ + ( "#313D00", "#F9EF00" ), \ + ( "#17083B", "#4A00ED" ) ] +#TRACK_COLORS = [ ( "#00591B", "#00E847" ), \ +# ( "#6F1200", "#E72500" ), \ +# ( "#004682", "#0090EA" ), \ +# ( "#716D00", "#F9EF00" ), \ +# ( "#37187B", "#4A00ED" ) ] +BEAT_COLOR = "#999999" +BEAT_LINE_SIZE = 2 +PLAYHEAD_COLOR = "#666666" +PLAYHEAD_SIZE = 2 +PLAYHEAD_SIZE_DIV2 = PLAYHEAD_SIZE/2.0 +MARQUEE_COLOR = "#FFFFFF" +MARQUEE_SIZE = 2 + +PAGE_BORDER_SIZE = 2 +PAGE_SELECTED_BORDER_SIZE = 5 +PAGE_WIDTH = 100 +PAGE_HEIGHT = 25 + +PAGE_THUMBNAIL_WIDTH = 92 +PAGE_THUMBNAIL_WIDTH_DIV2 = PAGE_THUMBNAIL_WIDTH/2 +PAGE_THUMBNAIL_HEIGHT = 65 + +THUMBNAIL_TRACK_RECT = [ ( 2, 4, 83, 10 ), \ + ( 2, 14, 83, 10 ), \ + ( 2, 24, 83, 10 ), \ + ( 2, 34, 83, 10 ), \ + ( 2, 44, 83, 13 ) ] +THUMBNAIL_DRAG_COLOR = "#000000" +THUMBNAIL_TRACK_COLOR = "#FF0000" +THUMBNAIL_SELECTED_COLOR = "#2266FF" +THUMBNAIL_DISPLAYED_COLOR = "#CC1133" + +TOOLBAR_BCK_COLOR = '#404040' +WHITE_COLOR = '#FFFFFF' +### miniTamTam/SYNTHLAB SPECIFIC ### +INST_BCK_COLOR = '#999999' +PANEL_BCK_COLOR = '#CCCCCC' +PANEL_COLOR = '#CCCCCC' +SL_LINE_COLOR = "#666666" +SL_HIGHLIGHT_COLOR = "#FFFFFF" +SL_OVER_WIRE_COLOR = "#FFFFFF" +SL_OVER_GATE_COLOR = "#00FF18" +SL_OVER_GATE_REJECT_COLOR = "#B30000" +PANEL_RADIUS = 10 +PANEL_SPACING = 2 + +###Instrument Panel### +CATEGORY_BCK_COLOR = '#222222' +INSTRUMENT_GRID_COLOR = '#CCCCCC' + +###Welcome Screen Specific### +WS_PANEL_COLOR = '#404040' +WS_BCK_COLOR = '#CCCCCC' + +# hardware keycodes for mod keys +MOD_LSHIFT = 50 +MOD_RSHIFT = 62 +MOD_LCTRL = 37 +MOD_RCTRL = 109 +MOD_LALT = 64 +MOD_RALT = 113 + + + +######## +## Things that don't belong! +####### +class _ModKeys: + def __init__( self ): + self.shiftDown = False + self.ctrlDown = False + self.altDown = False + + def keyPress( self, code ): + if code == MOD_LSHIFT or code == MOD_RSHIFT: self.shiftDown = True + elif code == MOD_LCTRL or code == MOD_RCTRL: self.ctrlDown = True + elif code == MOD_LALT or code == MOD_RALT: self.altDown = True + + def keyRelease( self, code ): + if code == MOD_LSHIFT or code == MOD_RSHIFT: self.shiftDown = False + elif code == MOD_LCTRL or code == MOD_RCTRL: self.ctrlDown = False + elif code == MOD_LALT or code == MOD_RALT: self.altDown = False + +ModKeys = _ModKeys() + + +############ +## EDIT DEFAULTS +############ + +#DEFAULTS +PLAYER_TEMPO = 100 +PLAYER_TEMPO_LOWER = 30 +PLAYER_TEMPO_UPPER = 160 +DEFAULT_VOLUME = 50 + +#NUMERICAL CONSTANTS +NUMBER_OF_POSSIBLE_PITCHES = 25 +MINIMUM_PITCH = 24 +MAXIMUM_PITCH = MINIMUM_PITCH + NUMBER_OF_POSSIBLE_PITCHES - 1 +NUMBER_OF_POSSIBLE_PITCHES_DRUM = 13 +PITCH_STEP_DRUM = 2 +MINIMUM_PITCH_DRUM = 24 +MAXIMUM_PITCH_DRUM = MINIMUM_PITCH_DRUM + PITCH_STEP_DRUM*(NUMBER_OF_POSSIBLE_PITCHES_DRUM - 1) +MINIMUM_NOTE_DURATION = 1 # ticks +MS_PER_MINUTE = 60000.0 +TICKS_PER_BEAT = 12 +TICKS_PER_BEAT_DIV2 = TICKS_PER_BEAT/2 +MAXIMUM_BEATS = 12 # maximum beats per page +NUMBER_OF_TRACKS = 5 +NUMBER_OF_PAGES = 2 + +MINIMUM_AMPLITUDE = 0 +MAXIMUM_AMPLITUDE = 1 + +DEFAULT_GRID = 3 +DEFAULT_GRID_DIV2 = DEFAULT_GRID / 2.0 + + +#################### +## ToolTips +#################### +LANGUAGE = 'en' +exec 'from common.Resources.tooltips_%s import Tooltips' % LANGUAGE + + +#################### +## KeyMapping +#################### + +LOOP_KEYS = [17, 18, 19, 20, 21, 32, 33, 34, 35, 45, 46, 47, 48, 51, 60, 61] +# Key = Hardware Keycode Value = Note + +KEY_MAP_PIANO = {24:36, #Q + 25:38, #W + 26:40, #E + 27:41, #R + 28:43, #T + 29:45, #Y + 30:47, #U + 31:48, #I + + 11:37, #2 + 12:39, #3 + 14:42, #5 + 15:44, #6 + 16:46, #7 + + 39:25, #S + 40:27, #D + 42:30, #G + 43:32, #H + 44:34, #J + 46:37, #L + + 52:24, #Z + 53:26, #X + 54:28, #C + 55:29, #V + 56:31, #B + 57:33, #N + 58:35, #M + 59:36} #, + +KEY_MAP_NOTPIANO = {24:24, #Q + 25:25, #W + 26:26, #E + 27:27, #R + 28:28, #T + 29:29, #Y + 30:30, #U + 31:31, #I + 32:32, #O + 33:33, #P + + 38:34, #A + 39:35, #S + 40:36, #D + 41:37, #F + 42:38, #G + 43:39, #H + 44:40, #J + 45:41, #K + 46:42, #L + + 52:43, #Z + 53:44, #X + 54:45, #C + 55:46, #V + 56:47, #B + 57:48} #N + +KEY_MAP = KEY_MAP_PIANO diff --git a/TamTamMini.activity/MANIFEST b/TamTamMini.activity/MANIFEST index d09b7cd..3fca9cf 100644 --- a/TamTamMini.activity/MANIFEST +++ b/TamTamMini.activity/MANIFEST @@ -1,6 +1,7 @@ MANIFEST NEWS setup.py +Config.py TamTamMini.py activity/activity-tamtam.svg activity/activity.info @@ -31,6 +32,7 @@ Mini/__init__.py Mini/lps.py Mini/miniTamTamMain.py Mini/miniToolbars.py +Mini/InstrumentPanel.py common/Util/Block.py common/__init__.py common/Config.py @@ -373,9 +375,6 @@ common/Resources/Images/winds.png common/Resources/Images/windssel.png common/Resources/Images/zap.png common/Resources/Images/zapsel.png -common/Resources/Loops/loop1.ttl -common/Resources/Loops/loop2.ttl -common/Resources/Loops/loop3.ttl common/Resources/Sounds/acguit common/Resources/Sounds/alarm common/Resources/Sounds/banjo diff --git a/TamTamMini.activity/Mini/Fillin.py b/TamTamMini.activity/Mini/Fillin.py index 162f8ef..8dfc23f 100644 --- a/TamTamMini.activity/Mini/Fillin.py +++ b/TamTamMini.activity/Mini/Fillin.py @@ -6,7 +6,7 @@ import gobject from RythmGenerator import * from common.Util.CSoundClient import new_csound_client from common.Util.NoteDB import Note -import common.Config as Config +import Config class Fillin: def __init__( self, nbeats, tempo, instrument, reverb, volume ): diff --git a/TamTamMini.activity/Mini/GenRythm.py b/TamTamMini.activity/Mini/GenRythm.py index 330e174..1132991 100644 --- a/TamTamMini.activity/Mini/GenRythm.py +++ b/TamTamMini.activity/Mini/GenRythm.py @@ -1,5 +1,5 @@ import random -import common.Config as Config +import Config from common.Generation.GenerationConstants import GenerationConstants from common.Generation.Utils import * diff --git a/TamTamMini.activity/Mini/InstrumentPanel.py b/TamTamMini.activity/Mini/InstrumentPanel.py new file mode 100644 index 0000000..3d93647 --- /dev/null +++ b/TamTamMini.activity/Mini/InstrumentPanel.py @@ -0,0 +1,379 @@ +#!/usr/bin/env python + +import pygtk +pygtk.require( '2.0' ) +import gtk + +import time + +import Config +from common.Util.ThemeWidgets import * +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.setInstrument = setInstrument + self.playInstrument = playInstrument + self.micRec = micRec + self.synthRec = synthRec + self.rowLen = rowLen + self.enterMode = enterMode + + self.instDic = _instDic + + self.loaded = False + self.loadData = {} + self.loadStage = [0,0,0] + if force_load: self.load() + + def configure( self, setInstrument = None, playInstrument = None, enterMode = False, micRec = None, synthRec = None, rowLen = 8 ): + + self.setInstrument = setInstrument + self.playInstrument = playInstrument + self.enterMode = enterMode + self.micRec = micRec + + if self.rowLen != rowLen: + self.rowLen = rowLen + self.prepareInstrumentTable( self.category ) + else: + self.rowLen = rowLen + + def load( self, timeout = -1 ): + if self.loaded: return True + if Config.DEBUG > 4: print "InstrumentPanel load", self.loadStage + + if self.loadStage[0] == 0: + color = gtk.gdk.color_parse(Config.PANEL_BCK_COLOR) + self.modify_bg(gtk.STATE_NORMAL, color) + self.loadStage[0] = 1 + if timeout >= 0 and time.time() > timeout: return False + + if self.loadStage[0] == 1: + self.tooltips = gtk.Tooltips() + self.loadStage[0] = 2 + if timeout >= 0 and time.time() > timeout: return False + + if self.loadStage[0] == 2: + self.instTable = None + self.recstate = False + self.lastInstrumentWidget = None + + self.mainVBox = gtk.VBox() + self.loadStage[0] = 3 + if timeout >= 0 and time.time() > timeout: return False + + if self.loadStage[0] == 3: + if not self.loadInstrumentList( timeout, self.loadStage ): + return False + self.loadStage[0] = 4 + if timeout >= 0 and time.time() > timeout: return False + + if self.loadStage[0] == 4: + if not self.loadToolbar( timeout, self.loadStage ): + return False + self.loadStage[0] = 5 + if timeout >= 0 and time.time() > timeout: return False + + if self.loadStage[0] == 5: + if self.instDic == None: + self.instDic = {} + self.loadStage[0] = 5.1 + else: + self.loadStage[0] = 6 + + if self.loadStage[0] == 5.1: + if not self.loadInstDic( self.instDic, timeout, self.loadStage ): + return False + self.loadStage[0] = 6 + if timeout >= 0 and time.time() > timeout: return False + + if self.loadStage[0] == 6: + self.loadInstrumentViewport() + self.loadStage[0] = 7 + if timeout >= 0 and time.time() > timeout: return False + + if self.loadStage[0] == 7: + self.prepareInstrumentTable() + self.loadStage[0] = 8 + if timeout >= 0 and time.time() > timeout: return False + + self.add(self.mainVBox) + self.show_all() + + self.loaded = True + return True + + def loadInstrumentList( self, timeout = -1, loadStage = [0,0,0] ): + + if loadStage[1] == 0: + self.instrumentList = { "all": [], "all.enterMode": [], "percussions.enterMode": [], "lab": [], "mic": [], "kit": [] } + for category in Config.CATEGORIES: + self.instrumentList[category] = [] + loadStage[1] = 1 + if timeout >= 0 and time.time() > timeout: return False + + if loadStage[1] == 1: + keys = Config.INSTRUMENTS.keys() + for i in range(loadStage[2], len(keys)): + key = keys[i] + instrument = Config.INSTRUMENTS[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': + self.instrumentList["all.enterMode"].append( key ) + if key[0:4] != 'drum' and key[0:4] != 'guid': + self.instrumentList[instrument.category].append( key ) + if instrument.category == "percussions": + self.instrumentList["percussions.enterMode"].append( key ) + if instrument.category == "kit": + self.instrumentList["kit"].append( key ) + loadStage[2] += 1 + if timeout >= 0 and time.time() > timeout: return False + + loadStage[1] = 2 + loadStage[2] = 0 + + self.instrumentList["mic"].sort() + self.instrumentList["lab"].sort() + + self.instrumentList["all"] += self.instrumentList["kit"] + self.instrumentList["mic"] + self.instrumentList["lab"] + self.instrumentList["all.enterMode"] += self.instrumentList["mic"] + self.instrumentList["lab"] + self.instrumentList["percussions"] += self.instrumentList["kit"] + self.instrumentList["people"] += self.instrumentList["mic"] + self.instrumentList["keyboard"] += self.instrumentList["lab"] + + loadStage[1] = 0 + return True + + def loadToolbar( self, timeout = -1, loadStage = [0,0,0] ): + if loadStage[1] == 0: + self.loadData["toolbarBox"] = gtk.HBox() + self.firstTbBtn = None + self.loadStage[1] = 1 + if timeout >= 0 and time.time() > timeout: return False + + for i in range(loadStage[1]-1, len(Config.CATEGORIES)): + category = Config.CATEGORIES[i] + if loadStage[2] == 0: + self.loadData["btnBox"] = RoundVBox(fillcolor = Config.CATEGORY_BCK_COLOR, bordercolor = Config.PANEL_BCK_COLOR, radius = Config.PANEL_RADIUS) + self.loadData["btnBox"].set_border_width(Config.PANEL_SPACING) + loadStage[2] = 1 + if timeout >= 0 and time.time() > timeout: return False + + if loadStage[2] == 1: + self.loadData["btn"] = ImageRadioButton(self.firstTbBtn,Config.IMAGE_ROOT + category + '.png', Config.IMAGE_ROOT + category + 'sel.png', Config.IMAGE_ROOT + category + 'sel.png') + loadStage[2] = 2 + if timeout >= 0 and time.time() > timeout: return False + + if self.firstTbBtn == None: + self.firstTbBtn = self.loadData["btn"] + self.loadData["btn"].connect('clicked',self.handleToolbarBtnPress,category) + self.loadData["btnBox"].add(self.loadData["btn"]) + self.loadData["toolbarBox"].pack_start(self.loadData["btnBox"],True,True) + + loadStage[2] = 0 + loadStage[1] += 1 + if timeout >= 0 and time.time() > timeout: return False + + self.mainVBox.pack_start(self.loadData["toolbarBox"],False,False) + + self.loadData.pop("btn") + self.loadData.pop("btnBox") + self.loadData.pop("toolbarBox") + loadStage[1] = 0 + return True + + def loadInstDic( self, instDic, timeout = -1, loadStage = [0,0,0] ): + + if loadStage[1] == 0: + self.firstInstButton = None + self.loadData["len"] = len(self.instrumentList['all']) + loadStage[1] = 1 + if timeout >= 0 and time.time() > timeout: return False + + + for i in range( loadStage[1]-1, self.loadData["len"] ): + instrument = self.instrumentList["all"][i] + if loadStage[2] == 0: + self.loadData["instBox"] = RoundVBox(fillcolor = Config.INST_BCK_COLOR, bordercolor = Config.INSTRUMENT_GRID_COLOR, radius = Config.PANEL_RADIUS) + self.loadData["instBox"].set_border_width(Config.PANEL_SPACING) + loadStage[2] = 1 + if timeout >= 0 and time.time() > timeout: return False + + if loadStage[2] == 1: + try: + self.loadData["instButton"] = ImageRadioButton(self.firstInstButton, Config.IMAGE_ROOT + instrument + '.png' , Config.IMAGE_ROOT + instrument + 'sel.png', Config.IMAGE_ROOT + instrument + 'sel.png') + except: + self.loadData["instButton"] = ImageRadioButton(self.firstInstButton, Config.IMAGE_ROOT + 'generic.png' , Config.IMAGE_ROOT + 'genericsel.png', Config.IMAGE_ROOT + 'genericsel.png') + loadStage[2] = 2 + if timeout >= 0 and time.time() > timeout: return False + + if loadStage[2] == 2: + self.loadData["instButton"].clickedHandler = self.loadData["instButton"].connect('clicked',self.handleInstrumentButtonClick, instrument) + self.loadData["instButton"].connect('enter',self.handleInstrumentButtonEnter, instrument) + loadStage[2] = 3 + if timeout >= 0 and time.time() > timeout: return False + + self.loadData["instBox"].pack_start(self.loadData["instButton"],False,False) + instDic[instrument] = self.loadData["instBox"] + if self.firstInstButton == None: + self.firstInstButton = self.loadData["instButton"] + loadStage[2] = 0 + if timeout >= 0 and time.time() > timeout: return False + + loadStage[1] += 1 + + self.loadData.pop("instBox") + self.loadData.pop("instButton") + self.loadData.pop("len") + loadStage[1] = 0 + return True + + def loadInstrumentViewport( self ): + self.instrumentBox = RoundHBox(fillcolor = Config.INSTRUMENT_GRID_COLOR, bordercolor = Config.PANEL_BCK_COLOR, radius = Config.PANEL_RADIUS) + + self.scrollWin = gtk.ScrolledWindow() + self.scrollWin.set_policy(gtk.POLICY_NEVER,gtk.POLICY_AUTOMATIC) + + self.tableEventBox = gtk.EventBox() + color = gtk.gdk.color_parse(Config.INSTRUMENT_GRID_COLOR) + self.tableEventBox.modify_bg(gtk.STATE_NORMAL, color) + + self.scrollWin.add_with_viewport(self.tableEventBox) + self.tableEventBox.get_parent().set_shadow_type( gtk.SHADOW_NONE ) + self.instrumentBox.pack_start(self.scrollWin,True,True,0) + self.mainVBox.pack_start(self.instrumentBox) + self.show_all() + + def prepareInstrumentTable(self,category = 'all'): + + self.category = category + + if self.enterMode: + if category == "all": category = "all.enterMode" + elif category == "percussions": category = "percussions.enterMode" + + if self.instTable != None: + for child in self.instTable.get_children()[:]: + self.instTable.remove(child) + self.tableEventBox.remove(self.instTable) + self.instTable.destroy() + + instrumentNum = len(self.instrumentList[category]) + instruments = self.instrumentList[category] + + cols = self.rowLen + if instrumentNum < cols: + cols = instrumentNum + rows = (instrumentNum // cols) + if instrumentNum % cols is not 0: #S'il y a un reste + rows = rows + 1 + + self.instTable = gtk.Table(rows,cols,True) + self.instTable.set_row_spacings(0) + self.instTable.set_col_spacings(0) + + for row in range(rows): + for col in range(cols): + if row*cols+col >= instrumentNum: + break + instBox = self.instDic[instruments[row*cols+col]] + self.instTable.attach(instBox, col, col+1, row, row+1, gtk.SHRINK, gtk.SHRINK, 0, 0) + + self.tableEventBox.add(self.instTable) + self.instTable.show_all() + + def selectFirstCat(self): + self.firstTbBtn.set_active(True) + + def handleToolbarBtnPress(self, widget, category): + if widget.get_active(): + self.prepareInstrumentTable(category) + + def handleInstrumentButtonClick(self,widget,instrument): + if widget.get_active() is True and self.recstate == False: + if self.setInstrument: + widget.event( gtk.gdk.Event( gtk.gdk.LEAVE_NOTIFY ) ) # fake the leave event + self.setInstrument(instrument) + if self.playInstrument: self.playInstrument(instrument) + if self.enterMode: + pass #Close the window + + def handleInstrumentButtonEnter(self,widget,instrument): + if self.enterMode and self.playInstrument: + self.playInstrument(instrument) + + def handleMicRecButtonClick(self,widget,mic): + self.recstate = False + self.setInstrument(mic) + if self.micRec: self.micRec(mic) + + def handleRecButtonPress(self,widget,btn): + self.recstate = True + btn.set_active(True) + + def set_activeInstrument(self,instrument, state): + if len(self.instDic) > 0: + for key in self.instDic: + if key == instrument: + btn = self.instDic[key].get_children()[0] + btn.handler_block(btn.clickedHandler) + btn.set_active(state) + btn.handler_unblock(btn.clickedHandler) + + +class DrumPanel( gtk.EventBox ): + def __init__(self, setDrum = None): + gtk.EventBox.__init__(self) + color = gtk.gdk.color_parse(Config.PANEL_BCK_COLOR) + self.modify_bg(gtk.STATE_NORMAL, color) + + self.setDrum = setDrum + self.instrumentList = [] + keys = Config.INSTRUMENTS.keys() + for key in Config.INSTRUMENTS.keys(): + if Config.INSTRUMENTS[key].category == "kit": + self.instrumentList.append( key ) + self.instrumentList.sort() + self.drawDrums() + + def drawDrums(self): + firstBtn = None + btnBox = RoundHBox(fillcolor = '#6F947B', bordercolor = Config.PANEL_BCK_COLOR, radius = Config.PANEL_RADIUS) + btnBox.set_border_width(Config.PANEL_SPACING) + self.drums = {} + for drumkit in self.instrumentList: + instBox = RoundVBox(fillcolor = Config.INST_BCK_COLOR, bordercolor = Config.PANEL_COLOR, radius = Config.PANEL_RADIUS) + instBox.set_border_width(Config.PANEL_SPACING) + self.drums[drumkit] = ImageRadioButton(firstBtn, Config.IMAGE_ROOT + drumkit + '.png' , Config.IMAGE_ROOT + drumkit + 'sel.png', Config.IMAGE_ROOT + drumkit + 'sel.png') + self.drums[drumkit].clickedHandler = self.drums[drumkit].connect('clicked',self.setDrums,drumkit) + if firstBtn == None: + firstBtn = self.drums[drumkit] + instBox.pack_start(self.drums[drumkit], False, False, 0) + btnBox.pack_start(instBox, False, False, 0) + self.add(btnBox) + self.show_all() + + def setDrums(self,widget,data): + if widget.get_active(): + if self.setDrum: + widget.event( gtk.gdk.Event( gtk.gdk.LEAVE_NOTIFY ) ) # fake the leave event + self.setDrum(data) + + def set_activeInstrument( self, instrument, state ): + if instrument in self.instrumentList: + btn = self.drums[instrument] + btn.handler_block(btn.clickedHandler) + btn.set_active(state) + btn.handler_unblock(btn.clickedHandler) + +if __name__ == "__main__": + win = gtk.Window() + wc = DrumPanel(None) + win.add(wc) + win.show() + #start the gtk event loop + gtk.main() diff --git a/TamTamMini.activity/Mini/KeyboardStandAlone.py b/TamTamMini.activity/Mini/KeyboardStandAlone.py index e3c3424..436c185 100644 --- a/TamTamMini.activity/Mini/KeyboardStandAlone.py +++ b/TamTamMini.activity/Mini/KeyboardStandAlone.py @@ -2,7 +2,7 @@ import pygtk pygtk.require( '2.0' ) import gtk -import common.Config as Config +import Config from common.Generation.GenerationConstants import GenerationConstants from common.Util.NoteDB import Note from common.Util.CSoundNote import CSoundNote diff --git a/TamTamMini.activity/Mini/Loop.py b/TamTamMini.activity/Mini/Loop.py index b36281e..61cb92c 100755 --- a/TamTamMini.activity/Mini/Loop.py +++ b/TamTamMini.activity/Mini/Loop.py @@ -1,4 +1,4 @@ -import common.Config as Config +import Config import random import lps from common.Generation.Drunk import * diff --git a/TamTamMini.activity/Mini/MiniSequencer.py b/TamTamMini.activity/Mini/MiniSequencer.py index 991ee13..639b684 100644 --- a/TamTamMini.activity/Mini/MiniSequencer.py +++ b/TamTamMini.activity/Mini/MiniSequencer.py @@ -3,7 +3,7 @@ pygtk.require( '2.0' ) import gtk import gobject import time -import common.Config as Config +import Config from common.Util.CSoundNote import CSoundNote from common.Util.CSoundClient import new_csound_client from common.Util.NoteDB import Note diff --git a/TamTamMini.activity/Mini/NoteStdAlone.py b/TamTamMini.activity/Mini/NoteStdAlone.py index 0dd4638..a331719 100644 --- a/TamTamMini.activity/Mini/NoteStdAlone.py +++ b/TamTamMini.activity/Mini/NoteStdAlone.py @@ -1,4 +1,4 @@ -import common.Config as Config +import Config from common.Util.CSoundClient import CSoundClient from common.Generation.GenerationConstants import GenerationConstants diff --git a/TamTamMini.activity/Mini/RythmGenerator.py b/TamTamMini.activity/Mini/RythmGenerator.py index 537f598..3231eb8 100644 --- a/TamTamMini.activity/Mini/RythmGenerator.py +++ b/TamTamMini.activity/Mini/RythmGenerator.py @@ -1,6 +1,6 @@ import random -import common.Config as Config +import Config from common.Util.CSoundNote import CSoundNote from common.Generation.GenerationConstants import GenerationConstants from GenRythm import GenRythm diff --git a/TamTamMini.activity/Mini/miniTamTamMain.py b/TamTamMini.activity/Mini/miniTamTamMain.py index f3916a9..843c5fc 100644 --- a/TamTamMini.activity/Mini/miniTamTamMain.py +++ b/TamTamMini.activity/Mini/miniTamTamMain.py @@ -14,7 +14,7 @@ from common.Util.NoteDB import PARAMETER import common.Util.Network as Net -import common.Config as Config +import Config from Mini.miniToolbars import playToolbar from Mini.miniToolbars import recordToolbar @@ -31,7 +31,7 @@ from MiniSequencer import MiniSequencer from Loop import Loop from RythmGenerator import * from common.Util.Trackpad import Trackpad -from common.Util.InstrumentPanel import InstrumentPanel +from Mini.InstrumentPanel import InstrumentPanel from gettext import gettext as _ diff --git a/TamTamMini.activity/Mini/miniToolbars.py b/TamTamMini.activity/Mini/miniToolbars.py index 7fc518e..057262b 100644 --- a/TamTamMini.activity/Mini/miniToolbars.py +++ b/TamTamMini.activity/Mini/miniToolbars.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import gtk -import common.Config as Config +import Config from sugar.graphics.toolbutton import ToolButton from sugar.graphics.toggletoolbutton import ToggleToolButton diff --git a/TamTamMini.activity/TamTamMini.py b/TamTamMini.activity/TamTamMini.py index aa3393c..2030a10 100644 --- a/TamTamMini.activity/TamTamMini.py +++ b/TamTamMini.activity/TamTamMini.py @@ -8,11 +8,11 @@ import gtk import gobject import time -import common.Config as Config +import Config from common.Util.CSoundClient import new_csound_client from common.Util.Profiler import TP -from common.Util.InstrumentPanel import InstrumentPanel +from Mini.InstrumentPanel import InstrumentPanel from Mini.miniTamTamMain import miniTamTamMain from common.Util.Trackpad import Trackpad from gettext import gettext as _ -- cgit v0.9.1