d456b8e7ae7f7a447a156e6b4242639f225857d0
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
)
77 instrumentDescription
= self
.selectInstrument()
78 if not instrumentDescription
:
82 self
.runPlayingScreen(songFile
, playMode
, instrumentDescription
)
86 def selectSongAndOptions(self
, songFile
, playMode
, wiimoteIndex
) :
87 """ lance l'écran de paramétrage et retourne un tuple comportant :
88 - drapeau de sortie de l'application (booléen)
89 - chemin du fichier de la chanson
91 - wiimote sélectionnée (entier)
93 home
= Home(songPath
=SONG_FILE_PATH
,
96 wiimoteIndex
=wiimoteIndex
,
97 nwiimotes
=self
.nwiimotes
)
99 home
.connect(QUIT
, app
.quit
)
105 console
.debug("sortie de l'application")
107 actual_wiimotes
= self
.WT
.get_count()
109 self
.firstSong
= False
111 envLogger
.info('NEW_LOG_FILE')
112 console
.info('chanson : %s', home
.songFile
)
113 console
.info('mode : %s', home
.modeSelect
.value
)
114 if actual_wiimotes
is None :
115 console
.info('HID : souris')
116 elif actual_wiimotes
== 0 :
117 console
.info('HID : souris (pas de wiimote trouvée)')
119 console
.info('HID : wiimote %d', home
.selectedWiimote
.value
+ 1)
122 return (home
.exitApp
,
124 home
.selectedPlayMode
,
125 home
.selectedWiimoteIndex
)
127 def selectInstrument(self
) :
128 """ lance l'écran de sélection de l'instrument et retourne
129 un dictionnaire comportant la description de l'instrument
131 selector
= InstrumentSelector()
135 EventDispatcher
.reset()
136 instru
= selector
.selectedInstrument
138 console
.info('instrument : %s', instru
['name'])
139 console
.info('preset : %d', instru
['preset'])
140 console
.info('bank : %d', instru
['bank'])
141 console
.info('ajustement octave : %d', instru
['octave'])
144 def runPlayingScreen(self
, songFile
, playMode
, instrumentDescription
) :
145 """ Lance l'écran de jeu principal avec la chanson 'songFile' dans le mode 'playMode'
146 avec l'instrument midi 'instrumentDescription'.
148 playMode
= PLAYING_MODES_DICT
[playMode
]
149 bank
, preset
= instrumentDescription
['bank'], instrumentDescription
['preset']
150 octave
= instrumentDescription
['octave']
151 self
.synth
.adjust_octave(0, octave
)
152 self
.synth
.program_select(0, bank
, preset
)
153 if playMode
== PLAYING_MODES_DICT
['IMPRO'] :
154 playingScreen
= PlayingScreen(self
.synth
)
156 song
= musicXml2Song(songFile
)
157 playingScreen
= SongPlayingScreen(self
.synth
, song
, mode
=playMode
)
160 EventDispatcher
.reset()
164 """ Classe utilitaire pour singer l'api
165 de pygame_wiimouse en cas d'abscence de wiimote.
167 selectWimoteIndex
= 0
172 def selectWiimote(self
, i
):
174 def get_count(self
) :