简体   繁体   English

使用Arduino发送MIDI SysEx消息?

[英]Sending MIDI SysEx messages with the Arduino?

I would like to send a MIDI SysEx message like this to my Roland JX8P Synth. 我想将这样的MIDI SysEx消息发送到我的Roland JX8P Synth。

F0 41 36 06 21 20 01 22 1B F7 F0 41 36 06 21 20 01 22 1B F7

This message would alter the VCF cutoff frequency of the synth. 该消息将改变合成器的VCF截止频率。 1B is a variable hexadecimal value, swinging from 00 to 7F, relative to cutoff frequency. 1B是可变的十六进制值,相对于截止频率从00到7F摆动。

In the MIDI library I've found the documentation for sending a SysEx message. 在MIDI库中,我找到了发送SysEx消息的文档。

sendSysEx (int length, const byte *const array, bool ArrayContainsBoundaries=false)

From what I can tell bool ArrayContainsBoundaries specifies whether or not you want the library to include the F0 and F7 message start/stop tags (I don't so I'll set it to true). 从我可以告诉bool ArrayContainsBoundaries指定您是否希望库包含F0和F7消息开始/停止标记(我不这样做,我将其设置为true)。 Int length denotes the message length in bytes(my message is 10 bytes, so this will be 10). Int length表示消息长度(以字节为单位)(我的消息是10个字节,因此这将是10)。

What I'm confused about is the array. 我困惑的是阵列。 Instead of storing all the values in the array can I just specify them like this? 我可以像这样指定它们,而不是将所有值存储在数组中吗?

 MIDI.sendSysEx(10,0xF0 0x41 0x36 0x06 0x21 0x20 0x01 0x22 0x1B 0xF7,true);

Also, is adding the prefix 0x the correct way to specify the bytes here? 另外,添加前缀0x是否正确指定字节?

The basic answer is "no": 基本答案是“不”:

Your sendSysEx() function is looking for take two or three parameters: 你的sendSysEx()函数正在寻找两个或三个参数:

  • Length 长度
  • The array of data 数据数组
  • The flag whether the array contains boundaries or not. 数组是否包含边界的标志。 This one is optional: if you omit it the parameter will be treated as false 这个是可选的:如果省略它,参数将被视为false

By trying to pass your array data like this: 通过尝试传递您的数组数据,如下所示:

MIDI.sendSysEx(10,0xF0 0x41 0x36 0x06 0x21 0x20 0x01 0x22 0x1B 0xF7,true);

You are doing one of two things: 你正在做两件事之一:

  • As written above, it is just a syntax error: the compiler doesn't know how to parse the list of numeric literals not separated by anything. 如上所述,它只是一个语法错误:编译器不知道如何解析未被任何东西分隔的数字文字列表。
  • If you separated the items by a comma, the compiler says "Oh, he is passing 12 parameters. Let me look for a function that takes 12 integer parameters... oh, I don't have one. Sorry." 如果用逗号分隔项目,编译器会说“哦,他传递了12个参数。让我找一个带12个整数参数的函数......哦,我没有。抱歉。” That gives your no matching function for call to error. 这使得你no matching function for call to错误。

So, one way to call your function is like this: 所以,调用你的函数的一种方法是这样的:

byte data[] = { 0xF0, 0x41, 0x36, 0x06, 0x21, 0x20, 0x01, 0x22, 0x1B, 0xF7 };
sendSysEx(10, data, true);

In C++11 you can get closer to what you want by initializing the list in the function call, something like sendSysEx(10,{0xF0, 0x41, 0x36, 0x06, 0x21, 0x20, 0x01, 0x22, 0x1B, 0xF7}, true); 在C ++ 11中,您可以通过初始化函数调用中的列表来更接近您想要的内容,例如sendSysEx(10,{0xF0, 0x41, 0x36, 0x06, 0x21, 0x20, 0x01, 0x22, 0x1B, 0xF7}, true); , however, you'll find that might run into another problem (depending on your toolchain): the compiler may assume that your initializer lists like that are lists of int s, not byte s, which will also cause a compiler error, unless you specifically told your compiler to assume integer literals to be 8 bits. 但是,您会发现可能会遇到另一个问题(取决于您的工具链):编译器可能会假设您的初始化程序列表是int的列表,而不是byte s,这也会导致编译器错误,除非您特别告诉你的编译器假设整数文字为8位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM