Ça commence à le faire.
[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 from pywiiuse import pygame_wiimouse
22 from pywiiuse.PyWiiUse import IR_BELOW
23
24
25 class MinWii(object):
26
27 def __init__(self) :
28 LaunchScreen()
29 app = Desktop()
30 synth = Synth()
31
32 modeResolution = (1024,768)
33
34 pygame_wiimouse.init(1, 5) # look for 1, wait 5 seconds
35 n = pygame_wiimouse.get_count()
36 print '%d wiimotes' % n
37 WT = pygame_wiimouse.WT
38 WT.pause()
39 wm = pygame_wiimouse.Wiimote(0) # access the wiimote object
40 wm.enable_accels(0) # turn on acceleration reporting
41 wm.enable_ir(1, vres = modeResolution, position=IR_BELOW)
42
43 pygame.display.set_mode(modeResolution)
44 pygame.display.set_caption('MinWii')
45
46 while True :
47 # sélection de la chanson
48 home = Home(songPath=SONG_FILE_PATH)
49 home.connect(QUIT, app.quit)
50 app.run(home)
51 app.close(home)
52 returnValue = home.returnValue
53 if not returnValue :
54 break
55
56 # sélection de l'instrument
57 WT.resume()
58 selector = InstrumentSelector()
59 selector.run()
60 selector.stop()
61 pygame.event.clear()
62 EventDispatcher.reset()
63 instrumentDescription = selector.selectedInstrument
64
65 # lancement du lecteur / clavier
66 songFile = home.songFile
67 playMode = home.modeSelect.value
68 playMode = PLAYING_MODES_DICT[playMode]
69 song = musicXml2Song(songFile)
70 bank, preset = instrumentDescription['bank'], instrumentDescription['preset']
71 octave = instrumentDescription.get('octave', 0)
72 synth.adjust_octave(0, octave)
73 synth.program_select(0, bank, preset)
74 playingScreen = SongPlayingScreen(synth, song, mode=playMode)
75 playingScreen.run()
76 pygame.event.clear()
77 EventDispatcher.reset()
78 WT.pause()