Implémentation de Column (en cours).
[minwii.git] / src / logging / Log.py
1 '''
2 Created on 28 aout 2009
3
4 @author: Samuel Benveniste
5 '''
6
7 import os
8 import sys
9 import subprocess
10 import re
11
12 import pygame
13 import pygame.midi
14 import pickle
15
16 from gui.constants import *
17
18 from gui.PlayingScreen import PlayingScreen
19 from gui.SongPlayingScreen import SongPlayingScreen
20 from gui.InstrumentChoice import InstrumentChoice
21 from instruments.Instrument import Instrument
22 from cursor.WarpingCursor import *
23 from controllers.Wiimote import Wiimote
24 from songs.Song import Song
25
26
27 class Log:
28 '''
29 classdocs
30 '''
31
32
33 def __init__(self,eventLog,scale,extendedScale,cascade,song,mode,activeWiimotes,easyMode = True):
34 '''
35 Constructor
36 '''
37 self.eventLog = eventLog
38 self.scale = scale
39 self.extendedScale = extendedScale
40 self.cascade = cascade
41 self.song = song
42 self.activeWiimotes = activeWiimotes
43 self.mode = mode
44
45 if __name__ == '__main__':
46
47 f = file('../../saves/4-12-2009-B1-v50-1.mwi', 'r')
48 unpickler = pickle.Unpickler(f)
49 log = unpickler.load()
50 f.close()
51
52 pygame.init()
53 pygame.midi.init()
54 instruments = [Instrument(scaleDict["majorScale"], i + 1, "".join(["../instruments/instrumentImages/", instrumentImagePathList[i], ".jpg"]), octaves[i]) for i in range(9)]
55
56 joys = [[id,pygame.joystick.Joystick(id).get_name()] for id in range(pygame.joystick.get_count())]
57 for joy in joys:
58 if joy[1] in joyNames:
59 pygame.joystick.Joystick(joy[0]).init()
60
61 ports = [pygame.midi.get_device_info(id)[1] for id in range(pygame.midi.get_count())]
62 portOffset = ports.index(portNames[0])
63 print(portOffset)
64
65 modeResolution = (1024,768)
66 window = pygame.display.set_mode(modeResolution,pygame.FULLSCREEN)
67 screen = pygame.display.get_surface()
68 clock = pygame.time.Clock()
69 cursorImages=[['../cursor/cursorImages/black/10.png'],['../cursor/cursorImages/red/10.png'],['../cursor/cursorImages/blue/10.png'],['../cursor/cursorImages/green/10.png']]
70 durations = [75 for i in range(len(cursorImages[0]))]
71
72 wiimoteCount = 4
73 cursors = [WarpingCursor(None, cursorImages[i], durations, (300 * i, 300 * i),flashImage = '../cursor/cursorImages/black/flash.png' ) for i in range(wiimoteCount)]
74 wiimotes = [Wiimote(i, i + portOffset, None, None, cursors[i]) for i in range(wiimoteCount)]
75
76 if log.song != None :
77
78 if log.mode == 0 :
79 log.extendedScale = log.song.requiresExtendedScale
80 log.cascade = True
81 log.easyMode = True
82 elif log.mode == 1 :
83 log.extendedScale = log.song.requiresExtendedScale
84 log.cascade = True
85 log.easyMode = True
86 elif log.mode == 2:
87 log.extendedScale = log.song.requiresExtendedScale
88 log.cascade = False
89 log.easyMode = True
90 elif log.mode == 3:
91 log.extendedScale = True
92 log.cascade = False
93 log.easyMode = False
94
95 choice = InstrumentChoice(instruments, wiimotes, window, screen, clock, joys, portOffset,log.activeWiimotes, eventLog = log.eventLog,scaleFactor = songScaleFactor,replay = True)
96 play = SongPlayingScreen(choice, log.song,log.cascade, log.extendedScale,log.easyMode)
97
98 else:
99
100 if log.mode == 0 :
101 log.extendedScale = False
102 log.cascade = False
103 elif log.mode == 1 :
104 log.extendedScale = True
105 log.cascade = False
106 elif log.mode == 2:
107 log.extendedScale = False
108 log.cascade = True
109 elif log.mode == 3:
110 log.extendedScale = True
111 log.cascade = True
112
113 choice = InstrumentChoice(instruments, wiimotes, window, screen, clock, joys, portOffset,log.activeWiimotes,eventLog = log.eventLog,replay = True)
114 play = PlayingScreen(choice, None,log.cascade, log.extendedScale)
115
116 while play.backToInstrumentChoice == True :
117
118 for wiimote in wiimotes:
119 del wiimote.port
120
121 wiimotes = [Wiimote(i, i + portOffset, None, None, cursors[i]) for i in range(wiimoteCount)]
122 previousEventLog = play.eventLog
123
124 if log.song != None :
125 choice = InstrumentChoice(instruments, wiimotes,window, screen, clock, joys, portOffset, log.activeWiimotes,eventLog = previousEventLog, replay = True, scaleFactor = songScaleFactor)
126 play = SongPlayingScreen(choice, log.song, False, log.extendedScale,log.easyMode)
127 else:
128 choice = InstrumentChoice(instruments, wiimotes, log.window, screen, clock, joys, portOffset,log.activeWiimotes, eventLog = previousEventLog, replay = True)
129 play = PlayingScreen(choice, None, log.cascade, log.extendedScale)
130
131 for wiimote in wiimotes:
132 del wiimote.port
133
134 pygame.midi.quit()
135 pygame.quit()