多个 DCSlider 发送不同的控制值(Xcode) [英] Multiple DCSliders sending different control values (Xcode)
问题描述
这个问题可能非常具体,但我是新手,真的需要一些帮助.
This question may be very specific, but I'm new to all this and really need some help.
我正在构建一个 iPhone 合成器应用.我正在使用 DCSliders 和 DCKnobs(它们看起来比标准 UISliders 更好).
I'm building an iPhone synth app. I am using DCSliders an DCKnobs (they look nicer than the standard UISliders).
https://github.com/domesticcatsoftware/DCControls#readme
我也在使用 libpd(一个 Pure Data 库),因此音频 DSP 由嵌入式 Pure Data 补丁处理.
I am also working with libpd (a Pure Data library) so the audio DSP is handled by an embedded Pure Data patch.
我的界面中有多个 DCSlider 和 DCKnobs.我可以通过将类设置为 DCSlider 的委托,将控制值从滑块/旋钮发送到 Pure Data...
I have got multiple DCSliders and DCKnobs in my interface. I am able to send control values from the sliders/knobs to Pure Data by making a class the delegate of the DCSlider...
- (void)loadView {
[super loadView];
self.mySlider = [[[DCSlider alloc] initWithDelegate:self] autorelease];
self.mySlider.frame = CGRectMake(10.0, 10.0, 20.0, 120.0);
[self.view addSubview:self.mySlider];
}
然后我实现了一种方法,将控制值发送到 Pure Data 中的接收器...
Then I implement a method to send control values to a receiver in Pure Data...
- (void)controlValueDidChange:(float)value sender:(id)sender {
[PdBase sendFloat:value toReceiver:@"beatvol"];
}
一切正常.
问题是所有滑块都发送相同的控制值.
The problem is that all of the sliders are sending the same control values.
如何让每个 DCSlider 将独立的控制值发送到 Pure Data 中的不同接收器?
How do I get each of the DCSliders to send independent control values to different receivers in Pure Data?
推荐答案
您需要为滑块分配一个标签.然后在 controlValueDidChange:
中,您需要获取该标签并根据标签执行您的操作:
You need to assign a tag to your sliders. Then in controlValueDidChange:
you need to get that tag and do your actions according to the tags:
- (void)loadView
{
[super loadView];
mySlider = [[[DCSlider alloc] initWithDelegate:self] autorelease];
mySlider.frame = CGRectMake(10.0, 10.0, 20.0, 120.0);
mySlider.tag = 0;
[self.view addSubview: mySlider];
}
- (void)controlValueDidChange:(float)value sender:(id)sender
{
DCSlider * slider = (DCSlider *)sender;
switch (slider.tag)
{
case 0:
{
[PdBase sendFloat:value toReceiver:@"beatvol"];
}
break;
case 1:
{
/* do something for the 2nd slider */;
}
break;
}
}
这篇关于多个 DCSlider 发送不同的控制值(Xcode)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!