2 # -*- coding: utf-8 -*-
4 # NOTE - This is a test app to see how far jacklib can go
8 from PyQt4
.QtCore
import QTimer
, SIGNAL
9 from PyQt4
.QtGui
import QApplication
, QDialog
11 # Imports (Custom Stuff)
12 import jacklib
, ui_plugin_audio_gain
14 global x_left
, x_right
, v_left
, v_right
15 x_left
= x_right
= 1.0
16 v_left
= v_right
= 0.0
18 def process_callback(nframes
, arg
):
19 global x_left
, x_right
, v_left
, v_right
20 v_leftx
= v_rightx
= 0.0
22 p_in1
= jacklib
.translate_audio_port_buffer(jacklib
.port_get_buffer(in_port1
, nframes
))
23 p_in2
= jacklib
.translate_audio_port_buffer(jacklib
.port_get_buffer(in_port2
, nframes
))
24 p_out1
= jacklib
.translate_audio_port_buffer(jacklib
.port_get_buffer(out_port1
, nframes
))
25 p_out2
= jacklib
.translate_audio_port_buffer(jacklib
.port_get_buffer(out_port2
, nframes
))
27 for i
in range(nframes
):
28 p_out1
[i
] = p_in1
[i
]*x_left
29 p_out2
[i
] = p_in2
[i
]*x_right
31 if (abs(p_out1
[i
]) > v_leftx
):
32 v_leftx
= abs(p_out1
[i
])
34 if (abs(p_out2
[i
]) > v_rightx
):
35 v_rightx
= abs(p_out2
[i
])
43 class AudioGainW(QDialog
, ui_plugin_audio_gain
.Ui_AudioGainW
):
44 def __init__(self
, parent
=None):
45 super(AudioGainW
, self
).__init
__(parent
)
48 self
.refresh
= 60 #miliseconds
50 self
.dial_left
.setPixmap(2)
51 self
.dial_right
.setPixmap(2)
52 self
.dial_left
.setLabel("Left")
53 self
.dial_right
.setLabel("Right")
54 self
.lpeak
.setChannels(1)
55 self
.lpeak
.setMaximumWidth(20)
56 self
.lpeak
.setRefreshRate(self
.refresh
*2/3)
57 self
.rpeak
.setChannels(1)
58 self
.rpeak
.setMaximumWidth(20)
59 self
.rpeak
.setRefreshRate(self
.refresh
*2/3)
61 self
.connect(self
.dial_left
, SIGNAL("valueChanged(int)"), self
.checkValueL
)
62 self
.connect(self
.dial_right
, SIGNAL("valueChanged(int)"), self
.checkValueR
)
67 def checkValueL(self
, value
):
69 x_left
= (float(value
+50)/100)*2
71 def checkValueR(self
, value
):
73 x_right
= (float(value
+50)/100)*2
76 global v_left
, v_right
77 self
.lpeak
.displayMeter(1, v_left
)
78 self
.rpeak
.displayMeter(1, v_right
)
79 QTimer
.singleShot(self
.refresh
, self
.checkPeaks
)
81 #--------------- main ------------------
82 if __name__
== '__main__':
85 app
= QApplication(sys
.argv
)
87 client
= jacklib
.client_open("audio_gain_test", jacklib
.NullOption
, 0)
88 in_port1
= jacklib
.port_register(client
, "in-left", jacklib
.DEFAULT_AUDIO_TYPE
, jacklib
.PortIsInput
, 0)
89 in_port2
= jacklib
.port_register(client
, "in-right", jacklib
.DEFAULT_AUDIO_TYPE
, jacklib
.PortIsInput
, 0)
90 out_port1
= jacklib
.port_register(client
, "out-left", jacklib
.DEFAULT_AUDIO_TYPE
, jacklib
.PortIsOutput
, 0)
91 out_port2
= jacklib
.port_register(client
, "out-right", jacklib
.DEFAULT_AUDIO_TYPE
, jacklib
.PortIsOutput
, 0)
93 jacklib
.set_process_callback(client
, process_callback
, 0)
94 jacklib
.activate(client
)
103 jacklib
.deactivate(client
)
104 jacklib
.client_close(client
)