I'm trying to create a new lib, but I'm having terrible issues.
When I try to import it, my code gets like
#include <
and Java crashes and starts to throw a lot of errors.
Here's the code of the .cpp
#include "Arduino.h"
#include "MidiMedia.h"
MidiMedia::MidiMedia(byte channel) {
byte aux;
byte pins[12] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
this.midiChannel = channel;
this.setKeyPins(pins);
for(aux = 0; aux <= 11; aux++) {
this.keyNotes[aux] = C + aux;
}
for(aux = 0; aux <= 11; aux++) { // Declara pinos de botões como saída com pull-up habilitado
pinMode(this.keyPins[aux], INPUT_PULLUP);
}
pinMode(UPPER_TRANSPOSER_BUTTON, INPUT_PULLUP);
pinMode(LOWER_TRANSPOSER_BUTTON, INPUT_PULLUP);
Serial.begin(115200); // Inicia comunicação serial
}
/*
*
*
MidiMedia::MidiMedia(byte channel, byte pins[12]) {
byte aux;
midiChannel = channel;
this.setKeyPins(pins);
for(aux = 0; aux <= 11; aux++) {
this.keyNotes[aux] = C + aux;
}
for(aux = 0; aux <= 11; aux++) { // Declara pinos de botões como saída com pull-up habilitado
pinMode(this.keyPins[aux], INPUT_PULLUP);
}
pinMode(UPPER_TRANSPOSER_BUTTON, INPUT_PULLUP);
pinMode(LOWER_TRANSPOSER_BUTTON, INPUT_PULLUP);
Serial.begin(115200); // Inicia comunicação serial
}
*
*
*/
void MidiMedia::transferData(byte midiFunction, byte pitch, byte velocity)
{ // Envia o dado MIDI por serial
byte midiMessage = midiFunction + this.midiChannel; // Associa o dado ao canal MIDI
Serial.write(midiMessage);
Serial.write(pitch);
Serial.write(velocity);
delay(1);
}
void MidiMedia::transpose(int transposer)
{
byte aux;
for(aux = 0; aux <= 11; aux++) {
this.keyNotes[aux] += transposer;
}
}
void MidiMedia::setKeyPins(byte pins[12])
{
byte aux;
for(aux = 0; aux <= 11; aux++) {
this.keyPins[aux] = pins[aux];
}
}
and the .h
/* Midi.h
* Biblioteca para envio de pacotes MIDI para o computador através da porta serial
* Otimizada para utilização com o shield MIDI Basics
* Desenvolvido por Jonathan Lopes Florêncio
* Universidade do Estado de Santa Catarina
*/
#ifndef MidiMedia_h
#define MidiMedia_h
#include "Arduino.h"
// Botões do transposer
#define UPPER_TRANSPOSER_BUTTON 15
#define LOWER_TRANSPOSER_BUTTON 14
// Botões das notas musicais
#define BUTTON_C 02
#define BUTTON_Cs 03
#define BUTTON_Db 03
#define BUTTON_D 04
#define BUTTON_Ds 05
#define BUTTON_Eb 05
#define BUTTON_E 06
#define BUTTON_Fa 07
#define BUTTON_Fs 08
#define BUTTON_Gb 08
#define BUTTON_G 09
#define BUTTON_Gs 10
#define BUTTON_Ab 10
#define BUTTON_A 11
#define BUTTON_As 12
#define BUTTON_Bb 12
#define BUTTON_B 13
// Notas musicais padrão - oitava central
#define C 60
#define Cs 61
#define Db 61
#define D 62
#define Ds 63
#define Eb 63
#define E 64
#define Fa 65
#define Fs 66
#define Gb 66
#define G 67
#define Gs 68
#define Ab 68
#define A 69
#define As 70
#define Bb 70
#define B 71
// Recursos do programa
#define MAX_VELOCITY 127
#define STANDARD_VELOCITY 64
#define ZERO_VELOCITY 0
// Funções MIDI
#define MIDI_NOTE_ON 0x90
#define MIDI_NOTE_OFF 0x80
#define MIDI_AFTERTOUCH 0xA0
#define MIDI_CONTINUOS_CONTROLLER 0xB0
#define MIDI_PATCH_CHANGE 0xC0
#define MIDI_CHANNEL_PRESSURE 0xD0
#define MIDI_PITCH_BEND 0xE0
#define MIDI_NON_MUSICAL_COMMANDS 0xF0
// Canais MIDI
#define MIDI_CHANNEL_00 0x00
#define MIDI_CHANNEL_01 0x01
#define MIDI_CHANNEL_02 0x02
#define MIDI_CHANNEL_03 0x03
#define MIDI_CHANNEL_04 0x04
#define MIDI_CHANNEL_05 0x05
#define MIDI_CHANNEL_06 0x06
#define MIDI_CHANNEL_07 0x07
#define MIDI_CHANNEL_08 0x08
#define MIDI_CHANNEL_09 0x09
#define MIDI_CHANNEL_10 0x0A
#define MIDI_CHANNEL_11 0x0B
#define MIDI_CHANNEL_12 0x0C
#define MIDI_CHANNEL_13 0x0D
#define MIDI_CHANNEL_14 0x0E
#define MIDI_CHANNEL_15 0x0F
class MidiMedia {
public:
MidiMedia(byte channel);
void transferData(byte midiFunction, byte pitch, byte velocity);
void transpose(int transposer);
byte keyPins[12];
byte keyNotes[12];
byte midiChannel;
};
#endif // MidiMedia.h
I don't know much abuot OOP, so these "class" things are kinda new for me. Does someone know what could be the problem?