Correction de typage.
[minwii.git] / src / minwii / config.py
1 # -*- coding: utf-8 -*-
2 """
3 constantes de configuration
4
5 $Id$
6 $URL$
7 """
8
9 import pygame
10 import os.path
11 from ConfigParser import ConfigParser
12
13 _here = os.path.abspath(__file__).split(os.path.sep)[:-1]
14
15 def _computePath(path) :
16 path = path.split('/')
17 path = _here + path
18 path = os.path.abspath(os.path.sep.join(path))
19 return path
20
21 def str2IntTuple(s) :
22 return tuple(map(int, s.strip('()').split(',')))
23
24
25 pygame.font.init()
26
27 conf = ConfigParser()
28
29 conf.add_section('playingscreen')
30 conf.set('playingscreen', 'FRAMERATE', '100')
31 conf.set('playingscreen', 'FIRST_HUE', '0.6')
32 conf.set('playingscreen', 'OFF_LUMINANCE', '0.2')
33 conf.set('playingscreen', 'OFF_SATURATION', '1')
34 conf.set('playingscreen', 'ON_TOP_LUMINANCE', '0.6')
35 conf.set('playingscreen', 'ON_BOTTOM_LUMINANCE', '0.9')
36 conf.set('playingscreen', 'ON_SATURATION', '1')
37 conf.set('playingscreen', 'ON_COLUMN_OVERSIZING', '2')
38 conf.set('playingscreen', 'ON_COLUMN_ALPHA', '1')
39 conf.set('playingscreen', 'FONT_COLOR', '(0,0,0)')
40 conf.set('playingscreen', 'MIDI_VELOCITY_RANGE', '(64, 127)')
41 conf.set('playingscreen', 'MIDI_PAN_RANGE', '(32, 96)')
42 conf.set('playingscreen', 'MIDI_VELOCITY_WRONG_NOTE_ATTN', '0.5')
43 conf.set('playingscreen', 'IR_POSITION', 'ABOVE')
44 conf.set('playingscreen', 'SCREEN_RESOLUTION', '(1024, 768)')
45
46 conf.add_section('locations')
47 conf.set('locations', 'notes_font_file', _computePath('fonts/Arial Unicode.ttf'))
48 conf.set('locations', 'SONG_FILE_PATH', _computePath('../chansons'))
49 conf.set('locations', 'LOGS_DIR', os.path.join(os.path.expanduser('~'), 'minwii_logs'))
50 conf.set('locations', 'SOUND_FONT', _computePath('soundfonts/Minwii-light-soundfont.sf2'))
51
52 # customisation
53 conf.read(_computePath('../minwii.ini'))
54
55 FRAMERATE = conf.getint('playingscreen', 'FRAMERATE')
56 FIRST_HUE = conf.getfloat('playingscreen', 'FIRST_HUE')
57 OFF_LUMINANCE = conf.getfloat('playingscreen', 'OFF_LUMINANCE',)
58 OFF_SATURATION = conf.getfloat('playingscreen', 'OFF_SATURATION')
59 ON_TOP_LUMINANCE = conf.getfloat('playingscreen', 'ON_TOP_LUMINANCE')
60 ON_BOTTOM_LUMINANCE = conf.getfloat('playingscreen', 'ON_BOTTOM_LUMINANCE')
61 ON_SATURATION = conf.getfloat('playingscreen', 'ON_SATURATION')
62 ON_COLUMN_OVERSIZING = conf.getfloat('playingscreen', 'ON_COLUMN_OVERSIZING')
63 ON_COLUMN_ALPHA = conf.getfloat('playingscreen', 'ON_COLUMN_ALPHA')
64 FONT_COLOR = str2IntTuple(conf.get('playingscreen', 'FONT_COLOR'))
65 MIDI_VELOCITY_RANGE = str2IntTuple(conf.get('playingscreen', 'MIDI_VELOCITY_RANGE'))
66 MIDI_PAN_RANGE = str2IntTuple(conf.get('playingscreen', 'MIDI_PAN_RANGE'))
67 MIDI_VELOCITY_WRONG_NOTE_ATTN = conf.getfloat('playingscreen', 'MIDI_VELOCITY_WRONG_NOTE_ATTN')
68 IR_POSITION = conf.get('playingscreen', 'IR_POSITION')
69 SCREEN_RESOLUTION = str2IntTuple(conf.get('playingscreen', 'SCREEN_RESOLUTION'))
70
71 SONG_FILE_PATH = conf.get('locations', 'SONG_FILE_PATH')
72 LOGS_DIR = conf.get('locations', 'LOGS_DIR')
73 SOUND_FONT = conf.get('locations', 'SOUND_FONT')
74
75 NOTES_FONT = pygame.font.Font(conf.get('locations', 'notes_font_file'), 50)
76 LYRICS_FONT = pygame.font.Font(None, 80)
77
78 instruments = ConfigParser()
79 instruments.add_section('accordeon')
80 instruments.set('accordeon', 'bank', '0')
81 instruments.set('accordeon', 'preset', '23')
82 instruments.set('accordeon', 'pos', '0')
83
84 instruments.add_section('carillon')
85 instruments.set('carillon', 'bank', '0')
86 instruments.set('carillon', 'preset', '8')
87 instruments.set('carillon', 'octave', '1')
88 instruments.set('carillon', 'pos', '1')
89
90 instruments.add_section('flute')
91 instruments.set('flute', 'bank', '0')
92 instruments.set('flute', 'preset', '73')
93 instruments.set('flute', 'pos', '2')
94
95 instruments.add_section('guitare')
96 instruments.set('guitare', 'bank', '0')
97 instruments.set('guitare', 'preset', '24')
98 instruments.set('guitare', 'octave', '-1')
99 instruments.set('guitare', 'pos', '3')
100
101 instruments.add_section('orgue')
102 instruments.set('orgue', 'bank', '0')
103 instruments.set('orgue', 'preset', '19')
104 instruments.set('orgue', 'pos', '4')
105
106 instruments.add_section('piano')
107 instruments.set('piano', 'bank', '0')
108 instruments.set('piano', 'preset', '0')
109 instruments.set('piano', 'pos', '5')
110
111 instruments.add_section('tuba')
112 instruments.set('tuba', 'bank', '0')
113 instruments.set('tuba', 'preset', '58')
114 instruments.set('tuba', 'octave', '-2')
115 instruments.set('tuba', 'pos', '6')
116
117
118 instruments.add_section('violon')
119 instruments.set('violon', 'bank', '0')
120 instruments.set('violon', 'preset', '40')
121 instruments.set('violon', 'pos', '7')
122
123 instruments.add_section('violoncelle')
124 instruments.set('violoncelle', 'bank', '0')
125 instruments.set('violoncelle', 'preset', '42')
126 instruments.set('violoncelle', 'octave', '-2')
127 instruments.set('violoncelle', 'pos', '8')
128
129 # customisation
130 instruments.read(_computePath('../instruments.ini'))
131
132
133 INSTRUMENTS = []
134 for section in instruments.sections() :
135 items = instruments.items(section)
136 instru = dict([(k, int(v)) for k, v in items])
137 instru['octave'] = instru.get('octave', 0)
138 instru['name'] = section
139 INSTRUMENTS.append(instru)
140
141 INSTRUMENTS.sort(lambda a, b : cmp(a['pos'], b['pos']))
142 map(lambda a : a.pop('pos'), INSTRUMENTS)
143
144 #INSTRUMENTS = (
145 # {'name' : 'violoncelle',
146 # 'bank' : 0,
147 # 'preset' : 42,
148 # 'octave' : -2
149 # },
150 #)
151 #
152 #for i in INSTRUMENTS :
153 # i['octave'] = i.get('octave', 0)
154
155
156 if __name__ == '__main__' :
157 for f in (conf, instruments) :
158 for section in f.sections() :
159 print '=== ', section, ' ==='
160 for k, v in f.items(section) :
161 print k, v
162 print '*'*80
163
164 from pprint import pprint
165 pprint(INSTRUMENTS)