-
Notifications
You must be signed in to change notification settings - Fork 0
/
configs.py
82 lines (67 loc) · 2.56 KB
/
configs.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
import os
from enum import Enum
from typing import Optional
import dill
from mapping import Mapping
from split import SplitData
class SlideMode(Enum):
FIXED = 1 # default cc74 to n
PRESS = 2 # cc74 is mapped to Channel Pressure
RELATIVE = 3 # calculated with respect to initial locked cc74 value (initial position is 64)
ABSOLUTE = 4 # zero damns given, just forward all cc74 messages as is.
BIPOLAR = 5 # starts at 0, either extreme will equal 127
class CONFIGS:
'''
Static Singleton class for storing global configuration data.
'''
MPE_MODE = True
SLIDE_MODE = SlideMode.RELATIVE
SLIDE_FIXED_N = 64
SPLITS = SplitData()
AUTO_SPLIT: Optional[SplitData] = None
'''
If true, MIDI mode will output each octave in its own channel, and SPLITS will be ignored.
The interval between C4 and C5 in the mapping will be used to determine octave offset in edosteps.
This is useful for Pianoteq which allows multi-channel mode where channel N+1 is pitched
one octave higher than channel N. (useful for very large edos)
'''
PITCH_BEND_RANGE = 24
MAPPING: Mapping = None
TOGGLE_SUSTAIN = False
def read_configs() -> bool:
"""
Read saved CONFIG state.
:return: True if successfully read a config file from 'config.dill'
"""
if not os.path.isfile('config.dill'):
return False
print('loading saved configurations from config.dill')
try:
with open('config.dill', 'rb') as f:
c = dill.load(f)
CONFIGS.MPE_MODE = c['MPE_MODE']
CONFIGS.SLIDE_MODE = c['SLIDE_MODE']
CONFIGS.SLIDE_FIXED_N = c['SLIDE_FIXED_N']
CONFIGS.SPLITS = c['SPLITS']
CONFIGS.AUTO_SPLIT = c['AUTO_SPLIT']
CONFIGS.PITCH_BEND_RANGE = c['PITCH_BEND_RANGE']
CONFIGS.MAPPING = c['MAPPING']
CONFIGS.TOGGLE_SUSTAIN = c['TOGGLE_SUSTAIN']
except Exception:
print('failed to load saved configurations. Delete config.dill.')
return False
return True
def save_configs():
print('saving settings into config.dill')
with open('config.dill', 'wb') as f:
c = {
'MPE_MODE': CONFIGS.MPE_MODE,
'SLIDE_MODE': CONFIGS.SLIDE_MODE,
'SLIDE_FIXED_N': CONFIGS.SLIDE_FIXED_N,
'SPLITS': CONFIGS.SPLITS,
'AUTO_SPLIT': CONFIGS.AUTO_SPLIT,
'PITCH_BEND_RANGE': CONFIGS.PITCH_BEND_RANGE,
'MAPPING': CONFIGS.MAPPING,
'TOGGLE_SUSTAIN': CONFIGS.TOGGLE_SUSTAIN
}
dill.dump(c, f)