b279000d6d5f3c204e2a7d5ed7a337b0aa093708
[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 octave = instrumentDescription.get('octave', 0)
58 synth.adjust_octave(0, octave)
59 synth.program_select(0, bank, preset)
60 playingScreen = SongPlayingScreen(synth, song, mode=playMode)
61 playingScreen.run()
62 pygame.event.clear()
63 EventDispatcher.reset()