2 Created on 25 janv. 2010
4 @author: Samuel Benveniste
10 from pgu
import gui
as pguGui
12 from gui
import constants
14 from instruments
.Instrument
import Instrument
15 from songs
.Song
import Song
16 from cursor
.WarpingCursor
import *
17 from gui
.StaticFamiliarizer
import StaticFamiliarizer
18 from gui
.SongFamiliarizer
import SongFamiliarizer
19 from gui
.SongPlayingScreen
import SongPlayingScreen
20 from gui
.DummyInstrumentChoice
import DummyInstrumentChoice
21 from controllers
.Wiimote
import Wiimote
23 class LogPGUPlayer(pguGui
.Desktop
):
29 def __init__(self
,rate
):
33 self
.firstStepDurations
= []
34 self
.firstStepClicks
= []
35 self
.firstStepClicksIn
= []
37 self
.secondStepDurations
= []
38 self
.secondStepClicks
= []
39 self
.secondStepClicksIn
= []
41 self
.thirdStepDurations
= []
42 self
.thirdStepClicks
= []
43 self
.thirdStepClicksIn
= []
45 self
.songDurations
= []
47 self
.songClicksIn
= []
48 self
.songClicksPerMinute
= []
49 self
.songClicksInPerMinute
= []
50 self
.songTotalDurations
= []
52 self
.meanTimeBetweenNotes
= []
54 pguGui
.Desktop
.__init
__(self
)
56 self
.replayRate
= rate
57 #pguGui.theme.load('../data/themes/default')
59 self
.connect(pguGui
.QUIT
,self
.quit
,None)
61 main
= pguGui
.Container(width
=500, height
=400) #, background=(220, 220, 220) )
64 main
.add(pguGui
.Label("File Dialog Example", cls
="h1"), 20, 20)
67 td_style
= {'padding_right': 10}
70 t
.td( pguGui
.Label('File Name:') , style
=td_style
)
71 self
.input_file
= pguGui
.Input()
72 t
.td( self
.input_file
, style
=td_style
)
73 self
.browseButton
= pguGui
.Button("Browse...")
74 t
.td( self
.browseButton
, style
=td_style
)
75 self
.browseButton
.connect(pguGui
.CLICK
, self
.open_file_browser
, None)
77 self
.goButton
= pguGui
.Button("Go")
79 self
.goButton
.connect(pguGui
.CLICK
, self
.goButtonClicked
,None)
81 self
.quitButton
= pguGui
.Button("Fin")
82 self
.quitButton
.connect(pguGui
.CLICK
,self
.quit
,None)
84 t
.td( self
.browseButton
, style
=td_style
)
85 t
.td( self
.goButton
, style
=td_style
)
86 t
.td( self
.quitButton
, style
=td_style
)
92 #profile.run('app.run(main)')
94 def open_file_browser(self
,data
=None):
95 d
= pguGui
.FileDialog(path
= "../../../saves")
96 d
.connect(pguGui
.CHANGE
, self
.handle_file_browser_closed
, d
)
100 def handle_file_browser_closed(self
,dlg
):
101 if dlg
.value
: self
.input_file
.value
= dlg
.value
103 def goButtonClicked(self
,data
=None):
104 if self
.input_file
.value
.endswith(".fmwi"):
105 f
= file(self
.input_file
.value
, 'r')
106 unpickler
= pickle
.Unpickler(f
)
107 log
= unpickler
.load()
110 log
.eventLog
.setReplayRate(self
.replayRate
)
113 instruments
= [Instrument(log
.scale
, i
+ 1, "".join(["../instruments/instrumentImages/", constants
.instrumentImagePathList
[i
], ".jpg"]), constants
.octaves
[i
]) for i
in range(9)]
115 joys
= [[id,pygame
.joystick
.Joystick(id).get_name()] for id in range(pygame
.joystick
.get_count())]
117 if joy
[1] in constants
.joyNames
:
118 pygame
.joystick
.Joystick(joy
[0]).init()
120 ports
= [pygame
.midi
.get_device_info(id)[1] for id in range(pygame
.midi
.get_count())]
121 portOffset
= ports
.index(constants
.portNames
[0])
124 screen
= pygame
.display
.get_surface()
125 clock
= pygame
.time
.Clock()
126 cursorImages
=[['../cursor/cursorImages/black/10.png'],['../cursor/cursorImages/red/10.png'],['../cursor/cursorImages/blue/10.png'],['../cursor/cursorImages/green/10.png']]
127 durations
= [75 for i
in range(len(cursorImages
))]
133 song
= Song(constants
.scaleDict
["majorScale"],[3,9,6,4,1,8,5,7,2,10],True)
137 cursors
= [WarpingCursor(None, cursorImages
[i
], durations
, (300 * i
, 300 * i
),'../cursor/cursorImages/black/flash.png') for i
in range(wiimoteCount
)]
138 wiimotes
= [Wiimote(i
, i
+ portOffset
, None, instruments
[0], cursors
[i
]) for i
in range(wiimoteCount
)]
139 dummyInstrumentChoice
= DummyInstrumentChoice(wiimotes
, window
, screen
, clock
, joys
, portOffset
, log
.activeWiimotes
)
141 familiarize
= StaticFamiliarizer(wiimotes
, window
, screen
, clock
, joys
, portOffset
,log
.activeWiimotes
,level
= log
.level
,eventLog
= log
.eventLog
,replay
= True)
142 self
.fillStaticFamiliarizerStats(familiarize
)
143 elif log
.level
== 2 :
144 familiarize
= SongFamiliarizer(wiimotes
, window
, screen
, clock
, joys
, portOffset
,song
,log
.activeWiimotes
,casc
,extsc
,easyMode
,eventLog
= log
.eventLog
,replay
= True)
145 self
.fillSongFamiliarizerStats(familiarize
)
147 familiarize
= SongPlayingScreen(dummyInstrumentChoice
,constants
.songDict
["clairdelalune"],easyMode
= True,eventLog
= log
.eventLog
,replay
= True)
148 self
.fillSongStats(familiarize
)
150 while familiarize
.nextLevel
!= None :
151 if familiarize
.nextLevel
< 2 :
152 familiarize
= StaticFamiliarizer(wiimotes
, window
, screen
, clock
, joys
, portOffset
,log
.activeWiimotes
,level
= familiarize
.nextLevel
,eventLog
= familiarize
.eventLog
,replay
= True)
153 self
.fillStaticFamiliarizerStats(familiarize
)
154 elif familiarize
.nextLevel
== 2 :
155 familiarize
= SongFamiliarizer(wiimotes
, window
, screen
, clock
, joys
, portOffset
,song
,log
.activeWiimotes
,casc
,extsc
,easyMode
,eventLog
= familiarize
.eventLog
,replay
= True)
156 self
.fillSongFamiliarizerStats(familiarize
)
158 familiarize
= SongPlayingScreen(dummyInstrumentChoice
,constants
.songDict
["clairdelalune"],easyMode
= True,eventLog
= familiarize
.eventLog
,replay
= True)
159 self
.fillSongStats(familiarize
)
161 for wiimote
in wiimotes
:
165 self
.printStatsToFile()
167 def fillStaticFamiliarizerStats(self
,familiarizer
):
168 if familiarizer
.level
== 0 :
169 self
.firstStepClicks
.append(familiarizer
.clicks
)
170 self
.firstStepClicksIn
.append(familiarizer
.clicksIn
)
171 self
.firstStepDurations
.append(familiarizer
.duration
)
173 if familiarizer
.level
== 1 :
174 self
.secondStepClicks
.append(familiarizer
.clicks
)
175 self
.secondStepClicksIn
.append(familiarizer
.clicksIn
)
176 self
.secondStepDurations
.append(familiarizer
.duration
)
178 def fillSongFamiliarizerStats(self
,familiarizer
):
179 self
.thirdStepClicks
.append(familiarizer
.clicks
)
180 self
.thirdStepClicksIn
.append(familiarizer
.clicksIn
)
181 self
.thirdStepDurations
.append(familiarizer
.duration
)
183 def fillSongStats(self
,familiarizer
):
184 self
.songClicks
.append(familiarizer
.clicks
)
185 self
.songClicksIn
.append(familiarizer
.clicksIn
)
186 self
.songClicksPerMinute
.append(familiarizer
.clicksPerMinute
)
187 self
.songClicksInPerMinute
.append(familiarizer
.clicksInPerMinute
)
188 self
.songDurations
.append(familiarizer
.songDurations
)
189 self
.songTotalDurations
.append(familiarizer
.totalDuration
)
191 def statsToFormattedString(self
):
192 return("First step durations :\n"+"\n"+
193 str(self
.firstStepDurations
)+"\n"+"\n"+
194 "First step clicks :\n"+"\n"+
195 str(self
.firstStepClicks
)+"\n"+"\n"+
196 "First step clicksIn :\n"+"\n"+
197 str(self
.firstStepClicksIn
)+"\n"+"\n"+
198 "Second step durations :\n"+"\n"+
199 str(self
.secondStepDurations
)+"\n"+"\n"+
200 "Second step clicks :\n"+"\n"+
201 str(self
.secondStepClicks
)+"\n"+"\n"+
202 "Second step clicksIn :\n"+"\n"+
203 str(self
.secondStepClicksIn
)+"\n"+"\n"+
204 "Third step durations :\n"+"\n"+
205 str(self
.thirdStepDurations
)+"\n"+"\n"+
206 "Third step clicks :\n"+"\n"+
207 str(self
.thirdStepClicks
)+"\n"+"\n"+
208 "Third step clicksIn :\n"+"\n"+
209 str(self
.thirdStepClicksIn
)+"\n"+"\n"+
210 "song durations :\n"+"\n"+
211 str(self
.songDurations
)+"\n"+"\n"+
212 "song clicks :\n"+"\n"+
213 str(self
.songClicks
)+"\n"+"\n"+
214 "song clicksIn :\n"+"\n"+
215 str(self
.songClicksIn
)+"\n"+"\n"+
216 "song clicks per minute:\n"+"\n"+
217 str(self
.songClicksPerMinute
)+"\n"+"\n"+
218 "song clicksIn per minute :\n"+"\n"+
219 str(self
.songClicksInPerMinute
)+"\n"+"\n"+
220 "song total durations :\n"+"\n"+
221 str(self
.songTotalDurations
)+"\n"+"\n")
223 def printStatsToFile(self
,path
=None):
225 path
= self
.input_file
.value
.replace(".fmwi",".txt")
226 file = open(path
,"w")
227 file.write("Log ID : "+self
.input_file
.value
+"\n"+"\n")
228 file.write(self
.statsToFormattedString())
231 if __name__
== "__main__":
233 modeResolution
= (1024,768)
234 window
= pygame
.display
.set_mode(modeResolution
,pygame
.FULLSCREEN
)
235 logConfig
= LogPGUPlayer(10000)