corrections des liaisons entre les syllabes.
[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
45 conf.add_section('locations')
46 conf.set('locations', 'notes_font_file', _computePath('fonts/Arial Unicode.ttf'))
47 conf.set('locations', 'SONG_FILE_PATH', _computePath('../chansons'))
48 conf.set('locations', 'LOGS_DIR', os.path.join(os.path.expanduser('~'), 'minwii_logs'))
49 conf.set('locations', 'SOUND_FONT', _computePath('soundfonts/Minwii-light-soundfont.sf2'))
50
51 # customisation
52 conf.read(_computePath('../minwii.ini'))
53
54 FRAMERATE = conf.getint('playingscreen', 'FRAMERATE')
55 FIRST_HUE = conf.getfloat('playingscreen', 'FIRST_HUE')
56 OFF_LUMINANCE = conf.getfloat('playingscreen', 'OFF_LUMINANCE',)
57 OFF_SATURATION = conf.getfloat('playingscreen', 'OFF_SATURATION')
58 ON_TOP_LUMINANCE = conf.getfloat('playingscreen', 'ON_TOP_LUMINANCE')
59 ON_BOTTOM_LUMINANCE = conf.getfloat('playingscreen', 'ON_BOTTOM_LUMINANCE')
60 ON_SATURATION = conf.getfloat('playingscreen', 'ON_SATURATION')
61 ON_COLUMN_OVERSIZING = conf.getfloat('playingscreen', 'ON_COLUMN_OVERSIZING')
62 ON_COLUMN_ALPHA = conf.getfloat('playingscreen', 'ON_COLUMN_ALPHA')
63 FONT_COLOR = str2IntTuple(conf.get('playingscreen', 'FONT_COLOR'))
64 MIDI_VELOCITY_RANGE = str2IntTuple(conf.get('playingscreen', 'MIDI_VELOCITY_RANGE'))
65 MIDI_PAN_RANGE = str2IntTuple(conf.get('playingscreen', 'MIDI_PAN_RANGE'))
66 MIDI_VELOCITY_WRONG_NOTE_ATTN = conf.getfloat('playingscreen', 'MIDI_VELOCITY_WRONG_NOTE_ATTN')
67 IR_POSITION = conf.get('playingscreen', 'IR_POSITION')
68
69 SONG_FILE_PATH = conf.get('locations', 'SONG_FILE_PATH')
70 LOGS_DIR = conf.get('locations', 'LOGS_DIR')
71 SOUND_FONT = conf.get('locations', 'SOUND_FONT')
72
73 NOTES_FONT = pygame.font.Font(conf.get('locations', 'notes_font_file'), 50)
74 LYRICS_FONT = pygame.font.Font(None, 80)
75
76 instruments = ConfigParser()
77 instruments.add_section('accordeon')
78 instruments.set('accordeon', 'bank', '0')
79 instruments.set('accordeon', 'preset', '23')
80 instruments.set('accordeon', 'pos', '0')
81
82 instruments.add_section('carillon')
83 instruments.set('carillon', 'bank', '0')
84 instruments.set('carillon', 'preset', '8')
85 instruments.set('carillon', 'octave', '1')
86 instruments.set('carillon', 'pos', '1')
87
88 instruments.add_section('flute')
89 instruments.set('flute', 'bank', '0')
90 instruments.set('flute', 'preset', '73')
91 instruments.set('flute', 'pos', '2')
92
93 instruments.add_section('guitare')
94 instruments.set('guitare', 'bank', '0')
95 instruments.set('guitare', 'preset', '24')
96 instruments.set('guitare', 'octave', '-1')
97 instruments.set('guitare', 'pos', '3')
98
99 instruments.add_section('orgue')
100 instruments.set('orgue', 'bank', '0')
101 instruments.set('orgue', 'preset', '19')
102 instruments.set('orgue', 'pos', '4')
103
104 instruments.add_section('piano')
105 instruments.set('piano', 'bank', '0')
106 instruments.set('piano', 'preset', '0')
107 instruments.set('piano', 'pos', '5')
108
109 instruments.add_section('tuba')
110 instruments.set('tuba', 'bank', '0')
111 instruments.set('tuba', 'preset', '58')
112 instruments.set('tuba', 'octave', '-2')
113 instruments.set('tuba', 'pos', '6')
114
115
116 instruments.add_section('violon')
117 instruments.set('violon', 'bank', '0')
118 instruments.set('violon', 'preset', '40')
119 instruments.set('violon', 'pos', '7')
120
121 instruments.add_section('violoncelle')
122 instruments.set('violoncelle', 'bank', '0')
123 instruments.set('violoncelle', 'preset', '42')
124 instruments.set('violoncelle', 'octave', '-2')
125 instruments.set('violoncelle', 'pos', '8')
126
127 # customisation
128 instruments.read(_computePath('../instruments.ini'))
129
130
131 INSTRUMENTS = []
132 for section in instruments.sections() :
133 items = instruments.items(section)
134 instru = dict([(k, int(v)) for k, v in items])
135 instru['octave'] = instru.get('octave', 0)
136 instru['name'] = section
137 INSTRUMENTS.append(instru)
138
139 INSTRUMENTS.sort(lambda a, b : cmp(a['pos'], b['pos']))
140 map(lambda a : a.pop('pos'), INSTRUMENTS)
141
142 #INSTRUMENTS = (
143 # {'name' : 'violoncelle',
144 # 'bank' : 0,
145 # 'preset' : 42,
146 # 'octave' : -2
147 # },
148 #)
149 #
150 #for i in INSTRUMENTS :
151 # i['octave'] = i.get('octave', 0)
152
153
154 if __name__ == '__main__' :
155 for f in (conf, instruments) :
156 for section in f.sections() :
157 print '=== ', section, ' ==='
158 for k, v in f.items(section) :
159 print k, v
160 print '*'*80
161
162 from pprint import pprint
163 pprint(INSTRUMENTS)