forked from mrstibbons/impedance_tuby_py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
99 lines (73 loc) · 2.89 KB
/
main.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
import sys
import os
import ConfigParser as cp
from PyQt4.QtGui import QApplication
from imptube.gui import MainWindow
from imptube.audio import AudioController
from imptube.project import Project
from imptube.tube import Tube
AUDIO_CONFIG = os.path.dirname(__file__) + "/config/audio.cfg"
class ImpedanceTube(object):
def __init__(self):
self.qt_app = QApplication(sys.argv)
self.audio_controller = None
self.create_audio_controller()
self.current_project = None
self.current_tube = None
self.setup_gui()
def setup_gui(self):
self.main_window = MainWindow(self)
#TODO: Move this method to the AudioController class
def create_audio_controller(self):
parser = cp.SafeConfigParser()
parser.read(AUDIO_CONFIG)
sampling_rate = parser.getint('AudioConfig', 'sampling_rate')
chunk_size = parser.getint('AudioConfig', 'chunk_size')
input_device = parser.getint('AudioConfig', 'input_device')
output_device = parser.getint('AudioConfig', 'output_device')
form = parser.get('AudioConfig', 'format')
try:
signal_dir = parser.get('AudioConfig', 'signal_dir')
except cp.NoOptionError:
signal_dir = None
if form == 'float32':
form = 1
elif form == 'int8':
form = 16
elif form == 'int16':
form = 8
elif form == 'int24':
form = 4
elif form == 'int32':
form = 2
else:
raise ValueError('Unknown format in audio.cfg')
self.audio_controller = AudioController(chunk_size=chunk_size,
sampling_rate=sampling_rate,
sample_format=form,
signal_dir=signal_dir)
self.audio_controller.set_input_device(input_device)
self.audio_controller.set_output_device(output_device)
def start_app(self):
self.main_window.show()
self.qt_app.exec_()
def set_current_project(self, project):
self.current_project = project
def set_current_tube(self, tube):
self.current_tube = tube
def add_calibration(self, calibration):
self.current_tube.add_calibration_function(calibration)
def add_measurement(self, measurement):
self.current_project.add_measurement(measurement)
def remove_measurement(self, index):
self.current_project.remove_measurement(index)
def save_project(self, path):
self.current_project.save_to_file(path)
def load_project(self, path):
self.current_project = Project.load_from_file(path)
def save_tube(self, path):
self.current_tube.save_to_file(path)
def load_tube(self, path):
self.current_tube = Tube.load_from_file(path)
imp_tube = ImpedanceTube()
imp_tube.start_app()