2e65952dd299e1891f031f3b046259f1322f336f
[minwii.git] / src / app / minwii.py
1 # -*- coding: utf-8 -*-
2 """
3 l'application winwii
4
5 $Id$
6 $URL$
7 """
8
9 import pygame
10 from pgu.gui import Desktop
11 from pgu.gui import QUIT
12 from widgets.launch import LaunchScreen
13 from widgets.home import Home
14 from widgets.playingscreen import SongPlayingScreen, PlayingScreen
15 from widgets.instrumentselector import InstrumentSelector
16 from synth import Synth
17 from eventutils import EventDispatcher
18 from musicxml import musicXml2Song
19 from config import SONG_FILE_PATH
20 from globals import PLAYING_MODES_DICT
21
22 class MinWii(object):
23
24 def __init__(self) :
25 LaunchScreen()
26 app = Desktop()
27 synth = Synth()
28
29 modeResolution = (1024,768)
30 pygame.display.set_mode(modeResolution)
31 pygame.display.set_caption('MinWii')
32
33 while True :
34 # sélection de la chanson
35 home = Home(songPath=SONG_FILE_PATH)
36 home.connect(QUIT, app.quit)
37 app.run(home)
38 app.close(home)
39 returnValue = home.returnValue
40 if not returnValue :
41 break
42
43 # sélection de l'instrument
44 selector = InstrumentSelector()
45 selector.run()
46 selector.stop()
47 pygame.event.clear()
48 EventDispatcher.reset()
49 instrumentDescription = selector.selectedInstrument
50
51 # lancement du lecteur / clavier
52 songFile = home.songFile
53 playMode = home.modeSelect.value
54 playMode = PLAYING_MODES_DICT[playMode]
55 song = musicXml2Song(songFile)
56 bank, preset = instrumentDescription['bank'], instrumentDescription['preset']
57 synth.program_select(0, bank, preset)
58 playingScreen = SongPlayingScreen(synth, song, mode=playMode)
59 playingScreen.run()
60 pygame.event.clear()
61 EventDispatcher.reset()