1 # -*- coding: utf-8 -*-
10 from pgu
.gui
import Theme
11 from pgu
.gui
import Desktop
12 from pgu
.gui
import QUIT
13 from minwii
.widgets
.launch
import LaunchScreen
14 from minwii
.widgets
.home
import Home
15 from minwii
.widgets
.playingscreen
import SongPlayingScreen
, PlayingScreen
16 from minwii
.widgets
.instrumentselector
import InstrumentSelector
17 from minwii
.synth
import Synth
18 from minwii
.eventutils
import EventDispatcher
19 from minwii
.musicxml
import musicXml2Song
20 from minwii
.config
import SONG_FILE_PATH
21 from minwii
.config
import SCREEN_RESOLUTION
22 from minwii
.globals import PLAYING_MODES_DICT
23 from minwii
.log
import console
, LOG_FORMAT_VERSION
, envLogger
30 def __init__(self
, wiimoteSupport
=True, fullscreen
=False) :
31 envLogger
.info('winwii log format version : %s', LOG_FORMAT_VERSION
)
32 self
.wiimoteSupport
= wiimoteSupport
33 self
.fullscreen
= fullscreen
35 themedir
= __file__
.split(os
.path
.sep
)[:-1] + ['widgets', 'data', 'minwii_theme']
36 themedir
= os
.path
.sep
.join(themedir
)
37 theme
= Theme(themedir
)
38 self
.app
= Desktop(theme
=theme
)
40 self
.screenResolution
= SCREEN_RESOLUTION
41 envLogger
.info('résolution écran : %s', self
.screenResolution
)
46 def initWiimotes(self
) :
47 if self
.wiimoteSupport
:
48 from pywiiuse
import pygame_wiimouse
49 from minwii
.config
import IR_POSITION
50 pygame_wiimouse
.init(4, 5, self
.screenResolution
, IR_POSITION
) # look for 4, wait 5 seconds
51 self
.nwiimotes
= nwiimotes
= pygame_wiimouse
.get_count()
52 console
.debug('wiimotes found : %d', nwiimotes
)
53 self
.WT
= WT
= pygame_wiimouse
.WT
59 "séquençage de l'affichage des écrans"
62 displayFlags
= displayFlags | pygame
.FULLSCREEN
63 pygame
.display
.set_mode(self
.screenResolution
, displayFlags
)
64 pygame
.display
.set_caption('MINWii')
67 songFile
, playMode
, wiimoteIndex
= '', 'NORMAL', 0
71 exit
, songFile
, playMode
, wiimoteIndex
= \
72 self
.selectSongAndOptions(songFile
, playMode
, wiimoteIndex
)
75 WT
.selectWiimote(wiimoteIndex
)
78 instrumentDescription
= self
.selectInstrument()
79 if not instrumentDescription
:
83 self
.runPlayingScreen(songFile
, playMode
, instrumentDescription
)
88 def selectSongAndOptions(self
, songFile
, playMode
, wiimoteIndex
) :
89 """ lance l'écran de paramétrage et retourne un tuple comportant :
90 - drapeau de sortie de l'application (booléen)
91 - chemin du fichier de la chanson
93 - wiimote sélectionnée (entier)
95 home
= Home(songPath
=SONG_FILE_PATH
,
98 wiimoteIndex
=wiimoteIndex
,
99 nwiimotes
=self
.nwiimotes
)
101 home
.connect(QUIT
, app
.quit
)
107 console
.debug("sortie de l'application")
109 actual_wiimotes
= self
.WT
.get_count()
111 self
.firstSong
= False
113 envLogger
.info('NEW_LOG_FILE')
114 console
.info('chanson : %s', home
.songFile
)
115 console
.info('mode : %s', home
.modeSelect
.value
)
116 if actual_wiimotes
is None :
117 console
.info('HID : souris')
118 elif actual_wiimotes
== 0 :
119 console
.info('HID : souris (pas de wiimote trouvée)')
121 console
.info('HID : wiimote %d', home
.selectedWiimote
.value
+ 1)
124 return (home
.exitApp
,
126 home
.selectedPlayMode
,
127 home
.selectedWiimoteIndex
)
129 def selectInstrument(self
) :
130 """ lance l'écran de sélection de l'instrument et retourne
131 un dictionnaire comportant la description de l'instrument
133 selector
= InstrumentSelector()
137 EventDispatcher
.reset()
138 instru
= selector
.selectedInstrument
140 console
.info('instrument : %s', instru
['name'])
141 console
.info('preset : %d', instru
['preset'])
142 console
.info('bank : %d', instru
['bank'])
143 console
.info('ajustement octave : %d', instru
['octave'])
146 def runPlayingScreen(self
, songFile
, playMode
, instrumentDescription
) :
147 """ Lance l'écran de jeu principal avec la chanson 'songFile' dans le mode 'playMode'
148 avec l'instrument midi 'instrumentDescription'.
150 playMode
= PLAYING_MODES_DICT
[playMode
]
151 song
= musicXml2Song(songFile
)
152 bank
, preset
= instrumentDescription
['bank'], instrumentDescription
['preset']
153 octave
= instrumentDescription
['octave']
154 self
.synth
.adjust_octave(0, octave
)
155 self
.synth
.program_select(0, bank
, preset
)
156 playingScreen
= SongPlayingScreen(self
.synth
, song
, mode
=playMode
)
159 EventDispatcher
.reset()
163 """ Classe utilitaire pour singer l'api
164 de pygame_wiimouse en cas d'abscence de wiimote.
166 selectWimoteIndex
= 0
171 def selectWiimote(self
, i
):
173 def get_count(self
) :