From: pin Date: Tue, 1 Jun 2010 15:23:08 +0000 (+0000) Subject: refactoring du fichier de configuration. On peut maintenant modifier les paramètres... X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/commitdiff_plain/9ee138507f97c1dddedc10cb0d471bc201693e77?ds=inline refactoring du fichier de configuration. On peut maintenant modifier les paramètres de l'applicaition au moyen de minwii.ini et de instruments.ini. git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@216 fe552daf-6dbe-4428-90eb-1537e0879342 --- diff --git a/src/minwii/app.py b/src/minwii/app.py index dad8f6b..f9385f6 100755 --- a/src/minwii/app.py +++ b/src/minwii/app.py @@ -53,7 +53,7 @@ class MinWii(object): if self.fullscreen : displayFlags = displayFlags | pygame.FULLSCREEN pygame.display.set_mode(self.screenResolution, displayFlags) - pygame.display.set_caption('MinWii') + pygame.display.set_caption('MINWii') WT = self.WT while True : diff --git a/src/minwii/config.py b/src/minwii/config.py index f45ef84..4a36201 100755 --- a/src/minwii/config.py +++ b/src/minwii/config.py @@ -8,6 +8,7 @@ $URL$ import pygame import os.path +from ConfigParser import ConfigParser _here = os.path.abspath(__file__).split(os.path.sep)[:-1] @@ -17,72 +18,144 @@ def _computePath(path) : path = os.path.abspath(os.path.sep.join(path)) return path +def str2IntTuple(s) : + return tuple(map(int, s.strip('()').split(','))) + pygame.font.init() +conf = ConfigParser() + +conf.add_section('playingscreen') +conf.set('playingscreen', 'FRAMERATE', '100') +conf.set('playingscreen', 'FIRST_HUE', '0.6') +conf.set('playingscreen', 'OFF_LUMINANCE', '0.2') +conf.set('playingscreen', 'OFF_SATURATION', '1') +conf.set('playingscreen', 'ON_TOP_LUMINANCE', '0.6') +conf.set('playingscreen', 'ON_BOTTOM_LUMINANCE', '0.9') +conf.set('playingscreen', 'ON_SATURATION', '1') +conf.set('playingscreen', 'ON_COLUMN_OVERSIZING', '2') +conf.set('playingscreen', 'ON_COLUMN_ALPHA', '1') +conf.set('playingscreen', 'FONT_COLOR', '(0,0,0)') +conf.set('playingscreen', 'MIDI_VELOCITY_RANGE', '(64, 127)') +conf.set('playingscreen', 'MIDI_PAN_RANGE', '(32, 96)') +conf.set('playingscreen', 'MIDI_VELOCITY_WRONG_NOTE_ATTN', '0.5') + +conf.add_section('locations') +conf.set('locations', 'notes_font_file', _computePath('fonts/Arial Unicode.ttf')) +conf.set('locations', 'SONG_FILE_PATH', _computePath('../chansons')) +conf.set('locations', 'LOGS_DIR', os.path.join(os.path.expanduser('~'), 'minwii_logs')) +conf.set('locations', 'SOUND_FONT', _computePath('soundfonts/FluidR3_GM.sf2')) + +# customisation +conf.read(_computePath('../minwii.ini')) + +FRAMERATE = conf.getint('playingscreen', 'FRAMERATE') +FIRST_HUE = conf.getfloat('playingscreen', 'FIRST_HUE') +OFF_LUMINANCE = conf.getfloat('playingscreen', 'OFF_LUMINANCE',) +OFF_SATURATION = conf.getfloat('playingscreen', 'OFF_SATURATION') +ON_TOP_LUMINANCE = conf.getfloat('playingscreen', 'ON_TOP_LUMINANCE') +ON_BOTTOM_LUMINANCE = conf.getfloat('playingscreen', 'ON_BOTTOM_LUMINANCE') +ON_SATURATION = conf.getfloat('playingscreen', 'ON_SATURATION') +ON_COLUMN_OVERSIZING = conf.getfloat('playingscreen', 'ON_COLUMN_OVERSIZING') +ON_COLUMN_ALPHA = conf.getfloat('playingscreen', 'ON_COLUMN_ALPHA') +FONT_COLOR = str2IntTuple(conf.get('playingscreen', 'FONT_COLOR')) +MIDI_VELOCITY_RANGE = str2IntTuple(conf.get('playingscreen', 'MIDI_VELOCITY_RANGE')) +MIDI_PAN_RANGE = str2IntTuple(conf.get('playingscreen', 'MIDI_PAN_RANGE')) +MIDI_VELOCITY_WRONG_NOTE_ATTN = conf.getfloat('playingscreen', 'MIDI_VELOCITY_WRONG_NOTE_ATTN') + +SONG_FILE_PATH = conf.get('locations', 'SONG_FILE_PATH') +LOGS_DIR = conf.get('locations', 'LOGS_DIR') +SOUND_FONT = conf.get('locations', 'SOUND_FONT') -# playingscreen -FRAMERATE = 100 -FIRST_HUE = 0.6 -OFF_LUMINANCE = 0.2 -OFF_SATURATION = 1 -ON_TOP_LUMINANCE = 0.6 -ON_BOTTOM_LUMINANCE = 0.9 -ON_SATURATION = 1 -ON_COLUMN_OVERSIZING = 2 -ON_COLUMN_ALPHA = 1 -font_file = _computePath('fonts/Arial Unicode.ttf') -NOTES_FONT = pygame.font.Font(font_file, 50) +NOTES_FONT = pygame.font.Font(conf.get('locations', 'notes_font_file'), 50) LYRICS_FONT = pygame.font.Font(None, 80) -FONT_COLOR = (0,0,0) -MIDI_VELOCITY_RANGE = (64, 127) -MIDI_PAN_RANGE = (32, 96) -MIDI_VELOCITY_WRONG_NOTE_ATTN = 0.5 - -SONG_FILE_PATH = _computePath('../chansons') - -INSTRUMENTS = ( - {'name' : 'accordeon', - 'bank' : 0, - 'preset' : 23 - }, - {'name' : 'celesta', - 'bank' : 0, - 'preset' : 8, - 'octave' : 1 - }, - {'name' : 'flute', - 'bank' : 0, - 'preset' : 73 - }, - {'name' : 'guitare', - 'bank' : 0, - 'preset' : 24, - 'octave' : -1 - }, - {'name' : 'orgue', - 'bank' : 0, - 'preset' : 19 - }, - {'name' : 'piano', - 'bank' : 0, - 'preset' : 0 - }, - {'name' : 'tuba', - 'bank' : 0, - 'preset' : 58, - 'octave' : -2 - }, - {'name' : 'violon', - 'bank' : 0, - 'preset' : 40 - }, - {'name' : 'violoncelle', - 'bank' : 0, - 'preset' : 42, - 'octave' : -2 - }, -) - -for i in INSTRUMENTS : - i['octave'] = i.get('octave', 0) + +instruments = ConfigParser() +instruments.add_section('accordeon') +instruments.set('accordeon', 'bank', '0') +instruments.set('accordeon', 'preset', '23') +instruments.set('accordeon', 'pos', '0') + +instruments.add_section('celesta') +instruments.set('celesta', 'bank', '0') +instruments.set('celesta', 'preset', '8') +instruments.set('celesta', 'octave', '1') +instruments.set('celesta', 'pos', '1') + +instruments.add_section('flute') +instruments.set('flute', 'bank', '0') +instruments.set('flute', 'preset', '73') +instruments.set('flute', 'pos', '2') + +instruments.add_section('guitare') +instruments.set('guitare', 'bank', '0') +instruments.set('guitare', 'preset', '24') +instruments.set('guitare', 'octave', '-1') +instruments.set('guitare', 'pos', '3') + +instruments.add_section('orgue') +instruments.set('orgue', 'bank', '0') +instruments.set('orgue', 'preset', '19') +instruments.set('orgue', 'pos', '4') + +instruments.add_section('piano') +instruments.set('piano', 'bank', '0') +instruments.set('piano', 'preset', '0') +instruments.set('piano', 'pos', '5') + +instruments.add_section('tuba') +instruments.set('tuba', 'bank', '0') +instruments.set('tuba', 'preset', '58') +instruments.set('tuba', 'octave', '-2') +instruments.set('tuba', 'pos', '6') + + +instruments.add_section('violon') +instruments.set('violon', 'bank', '0') +instruments.set('violon', 'preset', '40') +instruments.set('violon', 'pos', '7') + +instruments.add_section('violoncelle') +instruments.set('violoncelle', 'bank', '0') +instruments.set('violoncelle', 'preset', '42') +instruments.set('violoncelle', 'octave', '-2') +instruments.set('violoncelle', 'pos', '8') + +# customisation +instruments.read(_computePath('../instruments.ini')) + + +INSTRUMENTS = [] +for section in instruments.sections() : + items = instruments.items(section) + instru = dict([(k, int(v)) for k, v in items]) + instru['octave'] = instru.get('octave', 0) + instru['name'] = section + INSTRUMENTS.append(instru) + +INSTRUMENTS.sort(lambda a, b : cmp(a['pos'], b['pos'])) +map(lambda a : a.pop('pos'), INSTRUMENTS) + +#INSTRUMENTS = ( +# {'name' : 'violoncelle', +# 'bank' : 0, +# 'preset' : 42, +# 'octave' : -2 +# }, +#) +# +#for i in INSTRUMENTS : +# i['octave'] = i.get('octave', 0) + + +if __name__ == '__main__' : + for f in (conf, instruments) : + for section in f.sections() : + print '=== ', section, ' ===' + for k, v in f.items(section) : + print k, v + print '*'*80 + + from pprint import pprint + pprint(INSTRUMENTS) \ No newline at end of file diff --git a/src/minwii/log.py b/src/minwii/log.py index abbb858..9e40e01 100755 --- a/src/minwii/log.py +++ b/src/minwii/log.py @@ -13,6 +13,7 @@ import pygame import logging import os import datetime +from config import LOGS_DIR as logsdir LOG_FORMAT_VERSION='1.0' hiddenEvents = {pygame.MOUSEMOTION:True, @@ -21,7 +22,6 @@ hiddenEvents = {pygame.MOUSEMOTION:True, #COLOVER:True, } -logsdir = os.path.join(os.path.expanduser('~'), 'minwii_logs') if not os.path.exists(logsdir) : os.mkdir(logsdir) diff --git a/src/minwii/start.py b/src/minwii/start.py index 849338f..a9d9582 100755 --- a/src/minwii/start.py +++ b/src/minwii/start.py @@ -9,13 +9,13 @@ $URL$ -def main(wiimoteSupport) : +def main(wiimoteSupport, fullscreen) : import pygame from app import MinWii pygame.init() - minwii = MinWii(wiimoteSupport=wiimoteSupport) + minwii = MinWii(wiimoteSupport=wiimoteSupport, fullscreen=fullscreen) minwii.run() - pygame.quit() + pygame.quit() if __name__ == "__main__" : from os.path import realpath, sep @@ -31,11 +31,15 @@ if __name__ == "__main__" : , help = u"désactivation du support des wiimotes" u" [%default]") + op.add_option("--fullscreen", dest="fullscreen" + , action="store_true" + , default=False + , help = u"activation du mode plein écran" + u" [%default]") options, args = op.parse_args() - wiimoteSupport = options.wiimoteSupport minwiipath = realpath(__file__).split(sep) minwiipath = minwiipath[:-2] minwiipath = sep.join(minwiipath) sys.path.insert(1, minwiipath) - main(wiimoteSupport) \ No newline at end of file + main(options.wiimoteSupport, options.fullscreen) diff --git a/src/minwii/synth.py b/src/minwii/synth.py index c1faee7..f8e8798 100755 --- a/src/minwii/synth.py +++ b/src/minwii/synth.py @@ -10,6 +10,7 @@ from fluidsynth import Synth as FSynth from log import console, envLogger, eventLogger import pygame import events +from config import SOUND_FONT class Synth(FSynth) : """ @@ -23,13 +24,7 @@ class Synth(FSynth) : FSynth.__init__(self, gain=gain, samplerate=samplerate) if not sfPath : - sfPath = realpath(__file__).split(sep) - sfPath = sfPath[:-1] - sfPath.append('soundfonts') - - sfPath.append('FluidR3_GM.sf2') - sfPath = sep.join(sfPath) - + sfPath = SOUND_FONT assert exists(sfPath) self.start()