forked from Drachenkaetzchen/nocturn-game
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathConfigurator.py
executable file
·133 lines (108 loc) · 4.14 KB
/
Configurator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/python2
# Configurator.py
from yaml import load, dump
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
#import pprint
from NocturnModel import NocturnModel, NocturnPage
from NocturnActions import PagerAction, MIDIAction
import Midder
class Configurator( object ):
pag = 'Pag'
but = 'But'
enc = 'Enc'
sli = 'Sli'
def __init__( self, configFile ):
self.file = None
#~ try:
self.file = self._openFile( configFile )
#~ except Exception:
#~ print "File read
#~ return
#~ self.pp = pprint.PrettyPrinter( indent = 4 )
def __del__( self ):
self.file.close()
def progToFile( self, nocturn ):
self.nocturn = nocturn
self._serialize()
def fileToProg( self, nocturn ):
self.nocturn = nocturn
self._parseFile()
return self.nocturn
def _openFile( self, configFile ):
return open( configFile, 'r+b' )
def _parseFile( self ):
pass
def _serialize( self ):
pass
class YAMLConfigurator( Configurator ):
def __init__( self, configFile ):
super( YAMLConfigurator, self ).__init__( configFile )
def _parseFile( self ):
if self.file:
data = load( self.file )
#~ self.pp.pprint(data)
pag = Configurator.pag
but = Configurator.but
enc = Configurator.enc
sli = Configurator.sli
ii = 0
while ( pag + str(ii) ) in data:
curPage = data[ pag + str(ii) ]
self.nocturn.addPage( NocturnPage( self.nocturn ) )
for jj in range(8):
if ( but + str(jj) ) in curPage:
curBut = curPage[ but + str(jj) ]
self.nocturn.setAction( ii, jj + 8,
self._genAction(curBut['Action'],
curBut['Data']) )
for jj in range(8):
if ( enc + str(jj) ) in curPage:
curEnc = curPage[ enc + str(jj) ]
self.nocturn.setAction( ii, jj,
self._genAction(curEnc['Action'],
curEnc['Data']) )
ii += 1
pb = data[ 'PermaBar' ]
for jj in range(8):
if ( but + str(jj) ) in pb:
curBut = pb[ but + str(jj) ]
self.nocturn.setPermaAction( jj,
self._genAction(curBut['Action'],
curBut['Data']) )
if ( sli + str(0) ) in pb:
curSli = pb[ sli + str(0) ]
self.nocturn.setPermaAction ( 8, self._genAction(curSli[ 'Action' ],
curSli[ 'Data' ]) )
if ( enc + str(0) ) in pb:
curEnc = pb[ enc + str(0) ]
self.nocturn.setPermaAction ( 9, self._genAction( curEnc[ 'Action' ],
curEnc[ 'Data' ]) )
def _genAction( self, actType, data ):
action = None
if actType == 'MIDI':
action = MIDIAction()
action.setMIDICommand( data )
action.setMidder( Midder.getMidder() )
elif actType == 'PAGE':
action = PagerAction( data )
return action
#~ def _serialize( self ):
#~ sd = dict()
#~ pag = 1
#~ for page in self.state.pages:
#~ pagID = 'Pag' + str(pag)
#~ sd[ pagID ] = dict()
#~ typID = "Enc"
#~ enc = 1
#~ for encoder in page.encoders:
#~ pag += 1
if __name__ == "__main__":
print "name is main!"
config = YAMLConfigurator( "test.yaml" )
nocturn = NocturnModel()
config.fileToProg( nocturn )
while True:
nocturn.poll()