Due. MIDI.sendNoteOn не работает

pahuchiy
Offline
Зарегистрирован: 04.03.2018

Хочу вывести с ардуинки ноту в vsti. Не получается. 

По порядку:

1. Загружаю скетч через programming USB

2. Перетыкаю кабель в Native USB

3. Запускаю софтовый VSTi и отмечаю ардуинку как входное устройство: http://prntscr.com/iuak75

И ничего не происходит. Софт проверенный. Мидиклавиатуру к нему подключал таким образом без проблем. Мышкой клавиши нажимаю - звук идёт.

Вариантов перепробовал массу, вот парочка основных:

#include <MIDI.h>
#if defined(USBCON)
#include <midi_UsbTransport.h>

static const unsigned sUsbTransportBufferSize = 16;
typedef midi::UsbTransport<sUsbTransportBufferSize> UsbTransport;

UsbTransport sUsbTransport;

MIDI_CREATE_INSTANCE(UsbTransport, sUsbTransport, MIDI);

#else // No USB available, fallback to Serial
MIDI_CREATE_DEFAULT_INSTANCE();
#endif
void setup() {
  MIDI.begin(4);               // Launch MIDI with default options
  Serial.begin(115200);            // input channel is set to 4
}

void loop() {

    MIDI.sendNoteOn(42,127,1);  // Send a Note
    MIDI.sendNoteOn(45, 127, 1);
    delay(1000);      // Wait for a second
    MIDI.sendNoteOff(42,0,1);
    MIDI.sendNoteOff(45,0,1);   // Stop the note

}
#include <MIDI.h>

#if defined(USBCON)
#include <midi_UsbTransport.h>

static const unsigned sUsbTransportBufferSize = 16;
typedef midi::UsbTransport<sUsbTransportBufferSize> UsbTransport;

UsbTransport sUsbTransport;

MIDI_CREATE_INSTANCE(UsbTransport, sUsbTransport, MIDI);

#else // No USB available, fallback to Serial
MIDI_CREATE_DEFAULT_INSTANCE();
#endif

// --

void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity)
{
    Serial.print("NoteOn  ");
    Serial.print(inNumber);
    Serial.print("\tvelocity: ");
    Serial.println(inVelocity);
}
void handleNoteOff(byte inChannel, byte inNumber, byte inVelocity)
{
    Serial.print("NoteOff ");
    Serial.print(inNumber);
    Serial.print("\tvelocity: ");
    Serial.println(inVelocity);
}

void setup() {
    Serial.begin(115200);
    pinMode(LED_BUILTIN, OUTPUT);
    while (!Serial);
    MIDI.begin();
    MIDI.setHandleNoteOn(handleNoteOn);
    MIDI.setHandleNoteOff(handleNoteOff);
    Serial.println("Arduino ready.");
}

void loop() {
    MIDI.read();
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  MIDI.sendNoteOn(0,127,1); //отправляем ноту из массива myNote[], соответствующую кнопке
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  MIDI.sendNoteOff(0,127,1); //отправляем ноту из массива myNote[], соответствующую кнопке
  delay(1000);       
            
            //digitalWrite(ledPin, HIGH); //Мигаем 13м пином    
}

 

pahuchiy
Offline
Зарегистрирован: 04.03.2018

частично разобрался. Вот этот код работает как надо:

/*
 * MIDIUSB_test.ino
 *
 * Created: 4/6/2015 10:47:08 AM
 * Author: gurbrinder grewal
 * Modified by Arduino LLC (2015)
 */ 

#include "MIDIUSB.h"

// First parameter is the event type (0x09 = note on, 0x08 = note off).
// Second parameter is note-on/note-off, combined with the channel.
// Channel can be anything between 0-15. Typically reported to the user as 1-16.
// Third parameter is the note number (48 = middle C).
// Fourth parameter is the velocity (64 = normal, 127 = fastest).

void noteOn(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOn);
}

void noteOff(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOff);
}

void setup() {
  Serial.begin(115200);
}

// First parameter is the event type (0x0B = control change).
// Second parameter is the event type, combined with the channel.
// Third parameter is the control number number (0-119).
// Fourth parameter is the control value (0-127).

void controlChange(byte channel, byte control, byte value) {
  midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
  MidiUSB.sendMIDI(event);
}

void loop() {
  Serial.println("Sending note on");
  noteOn(0, 48, 64);   // Channel 0, middle C, normal velocity
  MidiUSB.flush();
  delay(500);
  Serial.println("Sending note off");
  noteOff(0, 48, 64);  // Channel 0, middle C, normal velocity
  MidiUSB.flush();
  delay(1500);

  // controlChange(0, 10, 65); // Set the value of controller 10 on channel 0 to 65
}

 

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

А с каких это пор middle C стала 48?

pahuchiy
Offline
Зарегистрирован: 04.03.2018

это вопрос нужно адресовывать шишим заграничным друзьям

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

Вы хотите сказать, что "шиши друзья" перекорежили в своей библиотеке стандарт MIDI?

Ладно, раз Вы пишете, что получилось, скажите хотя бы на слух, что играет: до первой или до малой?

pahuchiy
Offline
Зарегистрирован: 04.03.2018

andriano пишет:

"шиши друзья"

нашим)))) издержки беспроводной клавиатуры

ок, напишу чуть позже что играет

 

pahuchiy
Offline
Зарегистрирован: 04.03.2018

на октаву ниже middle C

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

Ну так и должно быть.

Значит, просто в комментариях ошибка.