fe17218087548287345803d382dded5a7d3f11f0
1 # -*- coding: utf-8 -*-
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 log
import console
26 def __init__(self
, wiimoteSupport
=True) :
27 self
.wiimoteSupport
= wiimoteSupport
31 self
.screenResolution
= (1024,768)
35 def initWiimotes(self
) :
36 if self
.wiimoteSupport
:
37 from pywiiuse
import pygame_wiimouse
38 pygame_wiimouse
.init(4, 5, self
.screenResolution
) # look for 4, wait 5 seconds
39 self
.nwiimotes
= nwiimotes
= pygame_wiimouse
.get_count()
40 console
.debug('%d wiimotes found', nwiimotes
)
41 self
.WT
= WT
= pygame_wiimouse
.WT
47 "manage the screen sequence display"
49 pygame
.display
.set_mode(self
.screenResolution
)
50 pygame
.display
.set_caption('MinWii')
55 exit
, songFile
, playMode
, selectedWiimoteIndex
= self
.selectSongAndOptions()
58 WT
.selectWiimote(selectedWiimoteIndex
)
61 instrumentDescription
= self
.selectInstrument()
62 self
.runPlayingScreen(songFile
, playMode
, instrumentDescription
)
67 def selectSongAndOptions(self
) :
68 """ lance l'écran de paramétrage et retourne un tuple comportant :
69 - drapeau de sortie de l'application (booléen)
70 - chemin du fichier de la chanson
72 - wiimote sélectionnée (entier)
74 home
= Home(songPath
=SONG_FILE_PATH
,
75 nwiimotes
=self
.nwiimotes
)
77 home
.connect(QUIT
, app
.quit
)
82 actual_wiimotes
= self
.WT
.get_count()
83 if actual_wiimotes
is None :
84 msg
= 'chanson : %s\nmode : %s\nHID : souris'
85 msg
= msg
% (home
.songFile
,
86 home
.modeSelect
.value
)
87 elif actual_wiimotes
== 0 :
88 msg
= 'chanson : %s\nmode : %s\nHID : souris (pas de wiimote trouvée)'
89 msg
= msg
% (home
.songFile
,
90 home
.modeSelect
.value
)
92 msg
= 'chanson : %s\nmode : %s\nHID : wiimote %d'
93 msg
= msg
% (home
.songFile
,
94 home
.modeSelect
.value
,
95 home
.selectedWiimote
.value
+ 1)
101 home
.modeSelect
.value
,
102 home
.selectedWiimote
.value
)
104 def selectInstrument(self
) :
105 """ lance l'écran de sélection de l'instrument et retourne
106 un dictionnaire comportant la description de l'instrument
108 selector
= InstrumentSelector()
112 EventDispatcher
.reset()
113 return selector
.selectedInstrument
115 def runPlayingScreen(self
, songFile
, playMode
, instrumentDescription
) :
116 """ Lance l'écran de jeu principal avec la chanson 'songFile' dans le mode 'playMode'
117 avec l'instrument midi 'instrumentDescription'.
119 playMode
= PLAYING_MODES_DICT
[playMode
]
120 song
= musicXml2Song(songFile
)
121 bank
, preset
= instrumentDescription
['bank'], instrumentDescription
['preset']
122 octave
= instrumentDescription
.get('octave', 0)
123 self
.synth
.adjust_octave(0, octave
)
124 self
.synth
.program_select(0, bank
, preset
)
125 playingScreen
= SongPlayingScreen(self
.synth
, song
, mode
=playMode
)
128 EventDispatcher
.reset()
132 """ Classe utilitaire pour singer l'api
133 de pygame_wiimouse en cas d'abscence de wiimote.
135 selectWimoteIndex
= 0
140 def selectWiimote(self
, i
):
142 def get_count(self
) :