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, 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
)
59 console
.info('wiimote sélectionnée : %d', selectedWiimoteIndex
)
62 instrumentDescription
= self
.selectInstrument()
63 self
.runPlayingScreen(songFile
, playMode
, instrumentDescription
)
68 def selectSongAndOptions(self
) :
69 """ lance l'écran de paramétrage et retourne un tuple comportant :
70 - drapeau de sortie de l'application (booléen)
71 - chemin du fichier de la chanson
73 - wiimote sélectionnée (entier)
75 home
= Home(songPath
=SONG_FILE_PATH
,
76 nwiimotes
=self
.nwiimotes
)
78 home
.connect(QUIT
, app
.quit
)
81 #console.debug('wiimote selected: %d', home.selecctedWiimoteIndex)
84 home
.modeSelect
.value
,
85 home
.selectedWiimote
.value
)
87 def selectInstrument(self
) :
88 """ lance l'écran de sélection de l'instrument et retourne
89 un dictionnaire comportant la description de l'instrument
91 selector
= InstrumentSelector()
95 EventDispatcher
.reset()
96 return selector
.selectedInstrument
98 def runPlayingScreen(self
, songFile
, playMode
, instrumentDescription
) :
99 """ Lance l'écran de jeu principal avec la chanson 'songFile' dans le mode 'playMode'
100 avec l'instrument midi 'instrumentDescription'.
102 playMode
= PLAYING_MODES_DICT
[playMode
]
103 song
= musicXml2Song(songFile
)
104 bank
, preset
= instrumentDescription
['bank'], instrumentDescription
['preset']
105 octave
= instrumentDescription
.get('octave', 0)
106 self
.synth
.adjust_octave(0, octave
)
107 self
.synth
.program_select(0, bank
, preset
)
108 playingScreen
= SongPlayingScreen(self
.synth
, song
, mode
=playMode
)
111 EventDispatcher
.reset()
115 selectWimoteIndex
= 0
120 def selectWiimote(self
, i
):