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
54 WT
.setEventCallBack(pygame_wiimouse
._default
_event
_cb
)
60 "séquençage de l'affichage des écrans"
63 displayFlags
= displayFlags | pygame
.FULLSCREEN
64 pygame
.display
.set_mode(self
.screenResolution
, displayFlags
)
65 pygame
.display
.set_caption('MINWii')
68 songFile
, playMode
, wiimoteIndex
= '', 'NORMAL', 0
73 exit
, songFile
, playMode
, wiimoteIndex
= \
74 self
.selectSongAndOptions(songFile
, playMode
, wiimoteIndex
)
77 WT
.selectWiimote(wiimoteIndex
)
79 instrumentDescription
= self
.selectInstrument()
80 if not instrumentDescription
:
83 self
.runPlayingScreen(songFile
, playMode
, instrumentDescription
)
87 def selectSongAndOptions(self
, songFile
, playMode
, wiimoteIndex
) :
88 """ lance l'écran de paramétrage et retourne un tuple comportant :
89 - drapeau de sortie de l'application (booléen)
90 - chemin du fichier de la chanson
92 - wiimote sélectionnée (entier)
94 home
= Home(songPath
=SONG_FILE_PATH
,
97 wiimoteIndex
=wiimoteIndex
,
98 nwiimotes
=self
.nwiimotes
)
100 home
.connect(QUIT
, app
.quit
)
106 console
.debug("sortie de l'application")
108 actual_wiimotes
= self
.WT
.get_count()
110 self
.firstSong
= False
112 envLogger
.info('NEW_LOG_FILE')
113 console
.info('chanson : %s', home
.songFile
)
114 console
.info('mode : %s', home
.modeSelect
.value
)
115 if actual_wiimotes
is None :
116 console
.info('HID : souris')
117 elif actual_wiimotes
== 0 :
118 console
.info('HID : souris (pas de wiimote trouvée)')
120 console
.info('HID : wiimote %d', home
.selectedWiimote
.value
+ 1)
123 return (home
.exitApp
,
125 home
.selectedPlayMode
,
126 home
.selectedWiimoteIndex
)
128 def selectInstrument(self
) :
129 """ lance l'écran de sélection de l'instrument et retourne
130 un dictionnaire comportant la description de l'instrument
132 selector
= InstrumentSelector()
136 EventDispatcher
.reset()
137 instru
= selector
.selectedInstrument
139 console
.info('instrument : %s', instru
['name'])
140 console
.info('preset : %d', instru
['preset'])
141 console
.info('bank : %d', instru
['bank'])
142 console
.info('ajustement octave : %d', instru
['octave'])
145 def runPlayingScreen(self
, songFile
, playMode
, instrumentDescription
) :
146 """ Lance l'écran de jeu principal avec la chanson 'songFile' dans le mode 'playMode'
147 avec l'instrument midi 'instrumentDescription'.
149 playMode
= PLAYING_MODES_DICT
[playMode
]
150 bank
, preset
= instrumentDescription
['bank'], instrumentDescription
['preset']
151 octave
= instrumentDescription
['octave']
152 self
.synth
.adjust_octave(0, octave
)
153 self
.synth
.program_select(0, bank
, preset
)
154 if playMode
== PLAYING_MODES_DICT
['IMPRO'] :
155 playingScreen
= PlayingScreen(self
.synth
)
157 song
= musicXml2Song(songFile
)
158 playingScreen
= SongPlayingScreen(self
.synth
, song
, mode
=playMode
)
161 EventDispatcher
.reset()
165 """ Classe utilitaire pour singer l'api
166 de pygame_wiimouse en cas d'abscence de wiimote.
168 selectWimoteIndex
= 0
173 def selectWiimote(self
, i
):
175 def get_count(self
) :