Keysets - eggmunkee/musipass GitHub Wiki

What is a keyset

A keyset is a python module that can override the sound function (and thus change the type of sound produced) and the mapping of pygame key codes to a distinct value used by the sound function. Below is a reference for those codes.

For example of the key code mapping, the default keyset maps each row of the keyboard and the column of the character into tuples like:

key_map = {
		K_z:			(0,1),
		K_x:			(0,2),
		K_c:			(0,3),

The default sound function uses the row (first component) number partially to determine what intervals (such as minor 3rd, major 3rd, etc.) to add on to the base note, which itself is based on the column number.

How keysets are loaded

Simply placing python scripts (must be .py) in the keysets folder of musipass will cause musipass to load each as a module and save that module object into a list. That list is what the user cycles through with the page up/page down keys.

Structure of a keyset

Each keyset module must have two variables to function: key_map and sound_func

Both of the variables can be set to None to use the default functionality.

key_map is expected to be a mapping type such as a dictionary. Each event loop, musipass checks if each key press's code is in the current key_map. If so, it takes the value for the entry in the key_map and passes that value on to sound_func to produce the sound as well as saving the value in the current password in memory.

sound_func takes three parameters: key_info, samp_rate, length

key_info is the value from key_map. samp_rate is the sample rate of the current sound system. length is a float for the number of seconds to play the sound. The default value is 0.07 seconds.

Pygame key codes

From pygame's docs here:

http://www.pygame.org/docs/ref/key.html

  K_EXCLAIM     !       exclaim
  K_QUOTEDBL    "       quotedbl
  K_HASH        #       hash
  K_DOLLAR      $       dollar
  K_AMPERSAND   &       ampersand
  K_QUOTE               quote
  K_LEFTPAREN   (       left parenthesis
  K_RIGHTPAREN  )       right parenthesis
  K_ASTERISK    *       asterisk
  K_PLUS        +       plus sign
  K_COMMA       ,       comma
  K_MINUS       -       minus sign
  K_PERIOD      .       period
  K_SLASH       /       forward slash
  K_0           0       0
  K_1           1       1
  K_2           2       2
  K_3           3       3
  K_4           4       4
  K_5           5       5
  K_6           6       6
  K_7           7       7
  K_8           8       8
  K_9           9       9
  K_COLON       :       colon
  K_SEMICOLON   ;       semicolon
  K_LESS        <       less-than sign
  K_EQUALS      =       equals sign
  K_GREATER     >       greater-than sign
  K_QUESTION    ?       question mark
  K_AT          @       at
  K_LEFTBRACKET [       left bracket
  K_BACKSLASH   \       backslash
  K_RIGHTBRACKET ]      right bracket
  K_CARET       ^       caret
  K_UNDERSCORE  _       underscore
  K_BACKQUOTE   `       grave
  K_a           a       a
  K_b           b       b
  K_c           c       c
  K_d           d       d
  K_e           e       e
  K_f           f       f
  K_g           g       g
  K_h           h       h
  K_i           i       i
  K_j           j       j
  K_k           k       k
  K_l           l       l
  K_m           m       m
  K_n           n       n
  K_o           o       o
  K_p           p       p
  K_q           q       q
  K_r           r       r
  K_s           s       s
  K_t           t       t
  K_u           u       u
  K_v           v       v
  K_w           w       w
  K_x           x       x
  K_y           y       y
  K_z           z       z