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