-
Notifications
You must be signed in to change notification settings - Fork 11
/
slider_values.py
49 lines (35 loc) · 2.13 KB
/
slider_values.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
from juce_init import START_JUCE_COMPONENT
import popsicle as juce
class MainContentComponent(juce.Component):
frequencySlider = juce.Slider()
frequencyLabel = juce.Label()
durationSlider = juce.Slider()
durationLabel = juce.Label()
def __init__(self):
juce.Component.__init__(self)
self.addAndMakeVisible(self.frequencySlider)
self.frequencySlider.setRange(50.0, 5000.0)
self.frequencySlider.setTextValueSuffix(" Hz")
self.frequencySlider.onValueChange = lambda: self.durationSlider.setValue(1.0 / self.frequencySlider.getValue(), juce.dontSendNotification)
self.addAndMakeVisible(self.frequencyLabel)
self.frequencyLabel.setText("Frequency", juce.dontSendNotification)
self.frequencyLabel.attachToComponent(self.frequencySlider, True)
self.addAndMakeVisible(self.durationSlider)
self.durationSlider.setRange(1.0 / self.frequencySlider.getMaximum(), 1.0 / self.frequencySlider.getMinimum())
self.durationSlider.setTextValueSuffix(" s")
self.durationSlider.onValueChange = lambda: self.frequencySlider.setValue (1.0 / self.durationSlider.getValue(), juce.dontSendNotification)
self.addAndMakeVisible(self.durationLabel)
self.durationLabel.setText("Duration", juce.dontSendNotification)
self.durationLabel.attachToComponent(self.durationSlider, True)
self.frequencySlider.setValue(500.0)
self.frequencySlider.setTextBoxStyle(juce.Slider.TextBoxLeft, False, 160, self.frequencySlider.getTextBoxHeight())
self.durationSlider.setTextBoxStyle(juce.Slider.TextBoxLeft, False, 160, self.durationSlider.getTextBoxHeight())
self.frequencySlider.setSkewFactorFromMidPoint(500)
self.durationSlider.setSkewFactorFromMidPoint(0.002)
self.setSize(600, 90)
def resized(self):
sliderLeft = 120
self.frequencySlider.setBounds(sliderLeft, 20, self.getWidth() - sliderLeft - 10, 20)
self.durationSlider.setBounds(sliderLeft, 50, self.getWidth() - sliderLeft - 10, 20)
if __name__ == "__main__":
START_JUCE_COMPONENT(MainContentComponent, name="Slider Values Example")