'class midi::MidiInterface<midi::SerialMIDI<HardwareSerial> >' has no member named 'getData1'

charnjit

Well-known member
I am trying playing waveforms sounds on Teensy4.1 from Teensy LC using Midi communication.
i will connect ( Teensy LC's Gnd to Teensy 4.1's Gnd) & ( Teensy LC's Tx to Teensy 4.1's Rx). to send Midi commands Teensy LC to Teensy4.1.
I upload below code succesfully to Teensy
Code:
#include <Keypad.h>                           
#include <MIDI.h>

const uint8_t ROWS = 8;  // 8 rows                        For TEENSY  LC as MIDI Keypoard
const uint8_t COLS = 8;  //8 columns   
char keys[ROWS][COLS] = {
{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},                 //  8 x 8
{41,42,43,44,45,46,47,48},
{49,50,51,52,53,54,55,56},
{57,58,59,60,61,62,63,64},
};
uint8_t rowPins[ROWS] = { 4,5,6,7,8,9,14,15  };    // 4,5,6,7,8,9,14,15         16,17,18,19,20,21,22,23
uint8_t colPins[COLS] = {16,17,18,19,20,21,22,23 };         
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
const int channel = 1;



void setup() {
     MIDI.begin();
    kpd.setHoldTime(2000);
    
}

void loop() {

        if (kpd.getKeys()) {
        for (int i = 0; i < LIST_MAX; i++) 
        {    int mykey = (kpd.key[i].kchar);
            if (kpd.key[i].stateChanged)  //  -----------------------------------------Key Changed----------------
            {      switch (kpd.key[i].kstate) {
                    case PRESSED:
                     MIDI.sendNoteOn(40+mykey, 127, 1);
                        break;
                         case RELEASED:
                          MIDI.sendNoteOff(40+mykey, 0, 1);
                        break;
                        
                }
            }  //--------------------------------------------------------------------------------------------------   
             if ((kpd.key[i].stateChanged)  && (mykey ==37))  //  -----------------------------------------Key Changed----------------
            {      switch (kpd.key[i].kstate) {
                    case PRESSED:
                      MIDI.sendProgramChange(5, 1);
                        break;
                }
            }  //--------------------------------------------------------------------------------------------------   
                    
        }
    }   
} //  -------------------------LOOP -------------------------------------------

when I try this code to Teensy4.1:
Code:
#include <Keypad.h> 
#include <Arduino.h>
#include <Audio.h>
#include <SD.h>
#include <TeensyVariablePlayback.h>
#include <SPI.h>
#include <Wire.h>
#include "PlaySynthMusic.h"
#include <MIDI.h>

const uint8_t ROWS = 7;  // 7 rows
const uint8_t COLS = 4;  //4 columns    //   Analog pin_22 ,  Enc (2,3)  ,
char keys[ROWS][COLS] = {
    { 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 }
};
uint8_t rowPins[ROWS] = { 33, 34, 35, 36, 37, 38, 39 }; 
uint8_t colPins[COLS] = { 40, 41, 14, 16 };         
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);


// GUItool: begin automatically generated code
AudioSynthWaveform       waveform1;      //xy=175.7142857142857,257.1428571428571
AudioSynthWaveform       waveform2;
AudioSynthWaveform       waveform3;
AudioSynthWaveform       waveform4;
AudioPlaySdResmp           playSdWav1;     //xy=185.00003814697266,190.0000171661377
AudioEffectEnvelope      envelope1;      //xy=324.2857131958008,255.7142848968506
AudioMixer4              mixer1;         //xy=754.2857494354248,214.28570938110352
AudioAmplifier           amp1;           //xy=949.9999656677246,191.42856407165527
AudioAmplifier           amp2;           //xy=952.8571510314941,242.8571376800537
AudioOutputI2S           i2s1;           //xy=1099.9999542236328,228.5714282989502
AudioConnection          patchCord1(waveform1, envelope1);
AudioConnection          patchCord2(waveform3, 0, mixer1, 0);
AudioConnection          patchCord3(playSdWav1, 1, mixer1, 1);
AudioConnection          patchCord4(envelope1, 0, mixer1, 2);
AudioConnection          patchCord9(waveform2, 0, mixer1, 3);
AudioConnection          patchCord5(mixer1, amp1);
AudioConnection          patchCord6(mixer1, amp2);
AudioConnection          patchCord7(amp1, 0, i2s1, 0);
AudioConnection          patchCord8(amp2, 0, i2s1, 1);
AudioControlSGTL5000     audioShield;     //xy=654.2857131958008,335.71429920196533
// GUItool: end automatically generated code

int RAGA[] = {50,52,54,55,57,59,61,62,64,66,67,69,71,73, 74,76,78};
int pitch[] = {100,277,311,329,370,415,440,493,554,622,659,740,830,880};
char *wav[] = {"WAV1", "WAV2", "WAV3","WAV4", "WAV5", "WAV6"};
    

MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);

void setup() {
      MIDI.begin(MIDI_CHANNEL_OMNI);
     Serial.begin(57600);
     kpd.setHoldTime(2000);
 

    if (!(SD.begin(BUILTIN_SDCARD))) {
        while (1) {      Serial.println("Unable to access the SD card");   delay(500);   }  }

    AudioMemory(128);
    audioShield.enable();
    audioShield.volume(1.0);
    amp1.gain(1.0);
    amp2.gain(1.0);
    playSdWav1.enableInterpolation(true);
     waveform1.begin(WAVEFORM_TRIANGLE);
      waveform2.begin(WAVEFORM_SQUARE);
       waveform3.begin(WAVEFORM_SINE);
      Serial.println(" Synth ");

}
   unsigned long t=0;
void loop() {
  if (kpd.getKeys()) {
        for (int i = 0; i < LIST_MAX; i++) 
        {    int mykey = (kpd.key[i].kchar);
            if ((kpd.key[i].stateChanged) && (mykey<29) && (mykey>0)) //  -----------------------------------------Key Changed----------------
            {      switch (kpd.key[i].kstate) {
                    case PRESSED:
                  
                        break;
                    case RELEASED:
              
                        break;
                }
            }  //--------------------------------------------------------------------------------------------------   
            
    } }   

// --------------------------------Read midi--------------------------------------------------------------
 int type, note, velocity, channel, d1, d2;
  if (MIDI.read()) {                    // Is there a MIDI message incoming ?
    uint8_t type = MIDI.getType();
    switch (type) {
      case midi::NoteOn:
        note = MIDI.getData1();
        velocity = MIDI.getData2();
        channel = MIDI.getChannel();
        if (velocity > 0) {
          Serial.println(String("Note On:  ch=") + channel + ", note=" + note + ", velocity=" + velocity);
        } else {
          Serial.println(String("Note Off: ch=") + channel + ", note=" + note);
        }
        break;
      case midi::NoteOff:
        note = MIDI.getData1();
        velocity = MIDI.getData2();
        channel = MIDI.getChannel();
        Serial.println(String("Note Off: ch=") + channel + ", note=" + note + ", velocity=" + velocity);
        break;
      default:
        d1 = MIDI.getData1();
        d2 = MIDI.getData2();
        Serial.println(String("Message, type=") + type + ", data = " + d1 + " " + d2);
    }
    t = millis();
  }
  if (millis() - t > 10000) {
    t += 10000;
    Serial.println("(inactivity)");
  }
    // --------------------------------Read Midi------------------------------------------------------------

              
}
I got error
Code:
'class midi::MidiInterface<midi::SerialMIDI<HardwareSerial> >' has no member named 'getData1'

how to fix it????
 
@charnjit: I was able to successfully compile your code here (Arduino IDE 1.8.19 + TD1.60b1 & Arduino IDE 2.3.4 + TD 0.60.1), with either "Serial + MIDI" or just "MIDI" selected as the "USB Type" & T4.1 as the "Board:". I did comment out the audio portions of your sketch (assuming that the problem you are looking to resolve is MIDI related, not audio related).

I would suggest that you reload both your IDE & your TeensyDuino, as it is possible that portions are either corrupt, or have been blocked/removed by your anti-virus protection.

Here's the actual code that I compiled, if you want to try it to verify . . .

Code:
#include <Keypad.h>
#include <Arduino.h>
#include <Audio.h>
#include <SD.h>
//#include <TeensyVariablePlayback.h>
#include <SPI.h>
#include <Wire.h>
//#include "PlaySynthMusic.h"
#include <MIDI.h>

const uint8_t ROWS = 7;  // 7 rows
const uint8_t COLS = 4;  //4 columns    //   Analog pin_22 ,  Enc (2,3)  ,
char keys[ROWS][COLS] = {
    { 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 }
};
uint8_t rowPins[ROWS] = { 33, 34, 35, 36, 37, 38, 39 };
uint8_t colPins[COLS] = { 40, 41, 14, 16 };         
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);


// GUItool: begin automatically generated code
//AudioSynthWaveform       waveform1;      //xy=175.7142857142857,257.1428571428571
//AudioSynthWaveform       waveform2;
//AudioSynthWaveform       waveform3;
//AudioSynthWaveform       waveform4;
//AudioPlaySdResmp           playSdWav1;     //xy=185.00003814697266,190.0000171661377
//AudioEffectEnvelope      envelope1;      //xy=324.2857131958008,255.7142848968506
//AudioMixer4              mixer1;         //xy=754.2857494354248,214.28570938110352
//AudioAmplifier           amp1;           //xy=949.9999656677246,191.42856407165527
//AudioAmplifier           amp2;           //xy=952.8571510314941,242.8571376800537
//AudioOutputI2S           i2s1;           //xy=1099.9999542236328,228.5714282989502
//AudioConnection          patchCord1(waveform1, envelope1);
//AudioConnection          patchCord2(waveform3, 0, mixer1, 0);
//AudioConnection          patchCord3(playSdWav1, 1, mixer1, 1);
//AudioConnection          patchCord4(envelope1, 0, mixer1, 2);
//AudioConnection          patchCord9(waveform2, 0, mixer1, 3);
//AudioConnection          patchCord5(mixer1, amp1);
//AudioConnection          patchCord6(mixer1, amp2);
//AudioConnection          patchCord7(amp1, 0, i2s1, 0);
//AudioConnection          patchCord8(amp2, 0, i2s1, 1);
//AudioControlSGTL5000     audioShield;     //xy=654.2857131958008,335.71429920196533
// GUItool: end automatically generated code

int RAGA[] = {50,52,54,55,57,59,61,62,64,66,67,69,71,73, 74,76,78};
int pitch[] = {100,277,311,329,370,415,440,493,554,622,659,740,830,880};
char *wav[] = {"WAV1", "WAV2", "WAV3","WAV4", "WAV5", "WAV6"};
    

MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);

void setup() {
      MIDI.begin(MIDI_CHANNEL_OMNI);
     Serial.begin(57600);
     kpd.setHoldTime(2000);
 

    if (!(SD.begin(BUILTIN_SDCARD))) {
        while (1) {      Serial.println("Unable to access the SD card");   delay(500);   }  }

//    AudioMemory(128);
//    audioShield.enable();
//    audioShield.volume(1.0);
//    amp1.gain(1.0);
//    amp2.gain(1.0);
//    playSdWav1.enableInterpolation(true);
//     waveform1.begin(WAVEFORM_TRIANGLE);
//      waveform2.begin(WAVEFORM_SQUARE);
//       waveform3.begin(WAVEFORM_SINE);
      Serial.println(" Synth ");

}
   unsigned long t=0;
void loop() {
  if (kpd.getKeys()) {
        for (int i = 0; i < LIST_MAX; i++)
        {    int mykey = (kpd.key[i].kchar);
            if ((kpd.key[i].stateChanged) && (mykey<29) && (mykey>0)) //  -----------------------------------------Key Changed----------------
            {      switch (kpd.key[i].kstate) {
                    case PRESSED:
                  
                        break;
                    case RELEASED:
              
                        break;
                }
            }  //--------------------------------------------------------------------------------------------------   
            
    } }   

// --------------------------------Read midi--------------------------------------------------------------
 int type, note, velocity, channel, d1, d2;
  if (MIDI.read()) {                    // Is there a MIDI message incoming ?
    uint8_t type = MIDI.getType();
    switch (type) {
      case midi::NoteOn:
        note = MIDI.getData1();
        velocity = MIDI.getData2();
        channel = MIDI.getChannel();
        if (velocity > 0) {
          Serial.println(String("Note On:  ch=") + channel + ", note=" + note + ", velocity=" + velocity);
        } else {
          Serial.println(String("Note Off: ch=") + channel + ", note=" + note);
        }
        break;
      case midi::NoteOff:
        note = MIDI.getData1();
        velocity = MIDI.getData2();
        channel = MIDI.getChannel();
        Serial.println(String("Note Off: ch=") + channel + ", note=" + note + ", velocity=" + velocity);
        break;
      default:
        d1 = MIDI.getData1();
        d2 = MIDI.getData2();
        Serial.println(String("Message, type=") + type + ", data = " + d1 + " " + d2);
    }
    t = millis();
  }
  if (millis() - t > 10000) {
    t += 10000;
    Serial.println("(inactivity)");
  }
    // --------------------------------Read Midi------------------------------------------------------------

              
}

Mark J Culross
KD5RXT
 
THANK YOU ,,,
I am using win7 32 Arduino 1.8.19 Teensyduino1.59 .
I was able to successfully compile your code here (Arduino IDE 1.8.19 + TD1.60b1
I could not see TD 1.60. on
Pjrc page
as i see on error , i seemed it is related to midi.but here i found another way to communicate these 2 boards .
Code:
#include <SoftwareSerial.h>
i succesfully upload code to both boards
i write in sender board : "101" for Note_On ,,,,, "mykey" for Note ,,,, "100" for Note_Off
Code:
 {    int mykey = (kpd.key[i].kchar);
            if (kpd.key[i].stateChanged)  //  -----------------------------------------Key Changed----------------
            {      switch (kpd.key[i].kstate) {
                    case PRESSED:
                    mySerial.write(101);
                     mySerial.write(mykey);
                        break;
                         case RELEASED:
                      mySerial.write(100);
                     mySerial.write(mykey);
                        break;
                        
                }
            }  //--------------------------------------------------------------------------------------------------
and trying to read it from Teensy 4.1 . when i use
Code:
// --------------------------------Read serial-------------------------------------------------------------
 int type, note, velocity, channel, d1, d2;
         if (mySerial.available())
    {

        Serial.println(mySerial.read());
 
      }
    // --------------------------------Read serial------------------------------------------------------------
serial monitor is printing right value
when i use:
Code:
// --------------------------------Read serial------------------------------------------------------------
 int type, note, velocity, channel, d1, d2;
         if (mySerial.available())
    {
      type = mySerial.read();
      note = mySerial.read();
   if (type==101) {  Serial.println(note);  Serial.println("on"); }
    else  if (type==100) {  Serial.println(note);   Serial.println("off");} 
      }
    // --------------------------------Read serial------------------------------------------------------------

i am getting "-1" for "note" variable. & "on" when type is 101 & "off" when type is 100
where is missing ??
how to assign variable "note" from "mySerial.read()"
 
Back
Top