]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blobdiff - helpers/mapping.py
Cleanup some constants
[perso/Immae/Projets/Python/MusicSampler.git] / helpers / mapping.py
index 84e99410874a979b7252329c245f152877582586..58aaf3d698461fed22e2913a5ffdb757e33dc597 100644 (file)
@@ -7,6 +7,15 @@ class Mapping:
     HEIGHT = 298
     SIZE   = WIDTH, HEIGHT
 
+    ROW_POSITIONS = {
+        'first':    0,
+        'second':  50,
+        'third':  100,
+        'fourth': 150,
+        'fifth':  200,
+        'sixth':  250,
+    }
+
     KEYS = [
         (pygame.K_ESCAPE, 'ESC', 'first',   0, {}),
 
@@ -26,17 +35,17 @@ class Mapping:
         (pygame.K_F12,    'F12', 'first', 700, {}),
 
 
-        (178,          '²', 'second',   0, {}),
+        (178,                 '²', 'second',   0, {}),
         (pygame.K_AMPERSAND,  '&', 'second',  50, {}),
-        (233,          'é', 'second', 100, {}),
+        (233,                 'é', 'second', 100, {}),
         (pygame.K_QUOTEDBL,   '"', 'second', 150, {}),
         (pygame.K_QUOTE,      "'", 'second', 200, {}),
         (pygame.K_LEFTPAREN,  '(', 'second', 250, {}),
         (pygame.K_MINUS,      '-', 'second', 300, {}),
-        (232,          'è', 'second', 350, {}),
+        (232,                 'è', 'second', 350, {}),
         (pygame.K_UNDERSCORE, '_', 'second', 400, {}),
-        (231,          'ç', 'second', 450, {}),
-        (224,          'à', 'second', 500, {}),
+        (231,                 'ç', 'second', 450, {}),
+        (224,                 'à', 'second', 500, {}),
         (pygame.K_RIGHTPAREN, ')', 'second', 550, {}),
         (pygame.K_EQUALS,     '=', 'second', 600, {}),
 
@@ -57,9 +66,9 @@ class Mapping:
         (pygame.K_CARET,      '^',   'third', 575, {}),
         (pygame.K_DOLLAR,     '$',   'third', 625, {}),
 
-        (pygame.K_RETURN, 'Enter', 'third', 692, { 'width': 56, 'height': 98 }),
+        (pygame.K_RETURN,   'Enter', 'third', 692, { 'width': 56, 'height': 98 }),
 
-        (pygame.K_CAPSLOCK,    'CAPS', 'fourth',  0, { 'width': 88, 'disabled': True }),
+        (pygame.K_CAPSLOCK, 'CAPS', 'fourth',  0, { 'width': 88, 'disabled': True }),
 
         (pygame.K_q,        'q', 'fourth',  90, {}),
         (pygame.K_s,        's', 'fourth', 140, {}),
@@ -71,7 +80,7 @@ class Mapping:
         (pygame.K_k,        'k', 'fourth', 440, {}),
         (pygame.K_l,        'l', 'fourth', 490, {}),
         (pygame.K_m,        'm', 'fourth', 540, {}),
-        (249,        'ù', 'fourth', 590, {}),
+        (249,               'ù', 'fourth', 590, {}),
         (pygame.K_ASTERISK, '*', 'fourth', 640, {}),
 
 
@@ -96,7 +105,7 @@ class Mapping:
         (pygame.K_LALT,     'LAlt',    'sixth', 165, { 'disabled': True }),
         (pygame.K_SPACE,    'Espace',  'sixth', 215, { 'width': 248 }),
         (pygame.K_MODE,     'AltGr',   'sixth', 465, { 'disabled': True }),
-        (314,        'Compose', 'sixth', 515, { 'disabled': True }),
+        (314,               'Compose', 'sixth', 515, { 'disabled': True }),
         (pygame.K_RCTRL,    'RCtrl',   'sixth', 565, { 'width': 63, 'disabled': True }),
 
 
@@ -122,7 +131,14 @@ class Mapping:
         self.keys = {}
         self.running = []
         for key in self.KEYS:
-            self.keys[key[0]] = Key(self, self.draw_lock, *key[0:4], **key[4])
+            if key[2] in self.ROW_POSITIONS:
+                position = self.ROW_POSITIONS[key[2]]
+            else:
+                position = key[2]
+            self.keys[key[0]] = Key(self,
+                    self.draw_lock,
+                    key[0], key[1], position, key[3],
+                    **key[4])
 
     def draw(self):
         for key_name in self.keys: