我正在使用 libpd 将 Pure Data 引擎嵌入到我的项目中,并且我正在尝试从补丁接收信号消息。
如果我在补丁中放置一个非信号消息(即)控件:
|
|
|
[s toCPP]
我在接收消息时没有遇到任何问题。但是,如果我尝试用 ~ 执行相同的消息,表示信号消息,我的处理程序永远不会收到它,示例补丁如下:
[osc~ 440]
|
|
|
[s~ toCPP]
无论我使用轮询还是回调,此补丁都不会收到任何“toCPP”消息。这是我的 [精简] 示例代码:
#include <PdBase.hpp>
#include <iostream>
using namespace pd;
class PdRec : public pd::PdReceiver
{
public:
void receiveFloat(const std::string & dest, float num)
{
std::cout << "received float: " << dest << ": " << num << std::endl;
}
void receiveSymbol(const std::string & dest, const std::string & symbol)
{
std::cout << "Received symbol: " << dest << ": " << symbol << std::endl;
}
void receiveMessage(const std::string & dest, const std::string & msg, const pd::List& list)
{
std::cout << "Received message: " << dest << ": " << msg << std::endl;
}
void receiveList(const std::string & dest, const pd::List & list)
{
std::cout << "Received list: " << dest << std::endl;
}
}
int main(int argc, char** argv)
{
float inbuf[64], outbuf[64];
pd::PdBase pdEngine;
if(!pdEngine.init(1, 1, 44100))
{
std::cout << "Failed to initialize pd!" << std::endl;
exit(1);
}
std::cout << "Init success!" << std::endl;
pd::Patch patch = pdEngine.openPatch("a440test.pd", "./");
std::cout << patch << std::endl;
PdRec rec;
pdEngine.subscribe("toCPP");
pdEngine.setReceiver(&rec);
pdEngine.computeAudio(true);
for(int i = 0; i < 30 * 44100 / 64; i++)
{
pdEngine.processFloat(1, inbuf, outbuf);
}
return 0;
}
人们希望此代码在每个报价周期从补丁接收一个 float (或 float 列表),用于符号 toCPP,但是,情况并非如此。此测试代码将接收消息的 [s toCPP] 版本,而不是 [s~ toCPP]。顺便说一句,如果我将 [osc~ 440] 连接到 [dac~] 对象并通过 outbuf 读取数据,我可以接收来自 [osc~ 440] 的输出,但这不是我的最佳选择使用并且我想避免它(主要原因是我可能需要输出超过 8 组或更多的声学数据,并且在补丁中创建和使用具有那么多 channel 的 dac~ 对象变得有些笨拙) .
因此我的问题是:
是否可以使用 libpd 从 Pd 补丁接收基于信号的消息?
如何在 C++ 端使用 libpd 从 Pd 补丁接收基于信号的消息?
最佳答案
在主机和 libpd 之间传递信号的唯一方法是使用[adc~]
和[dac~]
。
但是,您不需要创建具有“笨重”数量入口~的 [dac~]
。
改为使用 [dac~ 27]
在第 27 个 channel 上输出信号。
顺便说一句,没有“基于信号的消息”;消息是异步事件,而信号是同步数据流。
关于c++ - 如何使用 libpd 从纯数据补丁接收命名信号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24067250/