G’Day
I have a post in the Sound section of the forum regarding using a Midi library 国家动真格了,两会结束仅仅一月,社会已经发生了五大变化-成品片a免费入口蘑菇视 on a port other than 0 & 1. But my problem now is understanding Classes, so that I can use the NewSoftSerial library.
The example midi code has the code
class MyMidi : public Midi {
MyMidi(HardwareSerial &s) : Midi(s) {}
void handleNoteOn(unsigned int channel, unsigned int note, unsigned int velocity)
{ digitalWrite(13, HIGH);}
void handleNoteOff(unsigned int channel, unsigned int note, unsigned int velocity)
{ digitalWrite(13, LOW); }
};
What exactly is s as it’s not declared within the sketch.
By declaring
NewSoftSerial mySerial(10, 11);
Is changing
MyMidi(HardwareSerial &s) : Midi(s) {} to MyMidi(HardwareSerial &mySerial) : Midi(mySerial) {}
Correct?
I’m blindly altering code I do not understand.
Please use the # button then posting code.
s is a variable of type HardwareSerial, the class for the hardware serial on the Arduino board. If you want to change things from Hardware Serial to NewSoftSerial, it CAN (but I'm not sure) be enough to change HardwareSerial to NewSoftSerial.
JanD
Jan,
Tried that and got a error: expected ')' before '&' token.
Thats why I want to understand what the class stuff is all about.
Tried that and got a error: expected ')' before '&' token.
On what line? Post the whole file that generates the error.
The code is
[code#include "Midi.h"
#include "NewSoftSerial.h"
NewSoftSerial mySerial(10, 11);
class MyMidi : public Midi {
public:
//MyMidi(HardwareSerial mySerial) : Midi(mySerial) {}
MyMidi(mySerial &s) : Midi(s) {}
void handleNoteOn(unsigned int channel, unsigned int note, unsigned int velocity)
{
digitalWrite(13, HIGH);
}
void handleNoteOff(unsigned int channel, unsigned int note, unsigned int velocity)
{
digitalWrite(13, LOW);
}
};
// Create an instance of the MyMidi class.
//MyMidi midi(HardwareSerial);
MyMidi midi(mySerial);
//NewSoftSerial mySerial(10, 11);
void setup()
{
pinMode(13, OUTPUT);
mySerial.begin(31250);
midi.begin(0);
}
void loop()
{
midi.poll();
}
]
``
Your constructor is defined like so:
MyMidi(mySerial &s) : Midi(s) {}
The arguments must have types associated with them. s is an argument of type "address of mySerial". But, mySerial is not a type. HardwareSerial and NewSoftSerial are types.
Your constructor needs to look like:
MyMidi(HardwareSerial &s) : Midi(s) {}
or
MyMidi(NewSoftSerial &s) : Midi(s) {}
You can, of course, provide both constructors, so the class can be instanced with either hardware or software serial instances.
Starting to get the gist of what going on.
Did the edit to MyMidi(NewSoftSerial &s) : Midi(s) {}
Now an error at that line
No matching function for call to 'MyMidi(NewSoftSerial&)'
Post your modified code - header, source, and sketch, if they are not all in the same file.
The sketch is
#include "Midi.h"
#include "NewSoftSerial.h"
NewSoftSerial mySerial(2, 3);
class MyMidi : public Midi {
public:
MyMidi(NewSoftSerial &s) : Midi(s) {}
void handleNoteOn(unsigned int channel, unsigned int note, unsigned int velocity)
{ digitalWrite(13, HIGH); }
void handleNoteOff(unsigned int channel, unsigned int note, unsigned int velocity)
{ digitalWrite(13, LOW); }
};
MyMidi midi(mySerial);
void setup()
{
pinMode(13, OUTPUT);
mySerial.begin(31250);
midi.begin(0);
}
void loop()
{
midi.poll();
}/code]
Am using the Midi library from http://timothytwillman.com/itp_blog/?page_id=240
Which midi library are you deriving your class from?
Sorry, still having problems with the # key sequence to put code up.
Am using the Midi library from 国家动真格了,两会结束仅仅一月,社会已经发生了五大变化-成品片a免费入口蘑菇视
Grant
I tried downloading that library on Win7 64 bit. WinZip does not like that file at all. So, I can's compile your code to see exactly what gets highlighted. I suspect, though, that the Midi class constructor does not want a NewSortSerial object as input.
I can't confirm that, though, because I can't download the library.
Yup, I had the same problem with the download, used http://www.izarc.org/ and got it unzipped ok.
OK. I used that software to extract the data from the midi download, and it is as I expected. The Midi class does not support other than HardwareSerial instances.
Modifying the class so that it has an overloaded constructor that takes a NewSoftSerial instance would be easy. Implementing that method, and setting a field that indicated whether to use the hardware instance or software instance would be easy.
Modifying all the methods to use the hardware or software instance would not be hard, but there are a lot of them.
I'd take on the challenge, not that it is much of a challenge, but I don't have an Midi hardware to test the class with, or much interest in music with the Arduino. Hopefully, someone who does will take this on.
Paul, Tks for your time in this matter.
I'll put a hardware switch on the tx & rx line so that I can download sketch in one position, and then switch to MIDI.
tks again.
PaulS:
OK. I used that software to extract the data from the midi download, and it is as I expected. The Midi class does not support other than HardwareSerial instances.Modifying the class so that it has an overloaded constructor that takes a NewSoftSerial instance would be easy. Implementing that method, and setting a field that indicated whether to use the hardware instance or software instance would be easy.
Modifying all the methods to use the hardware or software instance would not be hard, but there are a lot of them.
I'd take on the challenge, not that it is much of a challenge, but I don't have an Midi hardware to test the class with, or much interest in music with the Arduino. Hopefully, someone who does will take this on.
Hey paul, if you wanted to make the modifications to the code, I have a working midi controller already on a breadboard, so testing it shouldn't be an issue..
As you know I already am familiar with the midi library being used and (thanks to you) working again... I wanted to investigate adding multiple midi inputs on my project so I knew I'd have to deal with nss eventually... This way we can help the community while furthering my project at the same time ![]()
I've modified the Midi class to be able to use either hardware or software serial port. I sent you a PM. If it works, you could post the revised code on the playground.
G'day.
Is it possible for me to check the new library. Have the MIDI hardware, plus the problem.
Could assist with the documentation etc.
Grant
Send me a PM with an e-mail address, and I'll send you the code.
Nick,
Any luck getting Pauls MIDI lib alterations tested.
Grant