Hi all,
I am trying to figure out how to play chords with a single midi note.
Eventually I want a single midi note to trigger then next chord in a sequence.
I used the audio plugin projucer template .
So many of the tutorials just have a header and main which makes it a little tricky for me to figure out where to put functions etc …
At this point I have declared a std::vector or vectors to store a basic chord sequence.
Its declared globally in PluginProcessor.cpp like this :
// global variables for plugin
int playing[127]; // array to hold notes playing
int numChords; // num of chords in chord sequence
int numNotes ; // number of notes in a chord
int note; // a midi note value
int chordsPosition = 0; // pointer to postion in chord array
vector<int> chord;
// initialize the chord array to 3 chords
vector< vector<int> > chords { { 60, 67 , 72 },
{ 72 , 79 , 84 },
{ 77, 84, 89 } };
I tried this in the process block but not much happened !
void WaylochorderAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
{
ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
buffer.clear();
MidiBuffer processedMidi;
int time;
MidiMessage m;
MidiBuffer midiBuffer;
// midi 58 resets the iterator
// midi 59 moves the iterator to the left
// 60 and 61 repeat the chord without moving the iterator
// 62 and up move through the sequence and if it gets to the end it resets to start
for (MidiBuffer::Iterator i (midiMessages); i.getNextEvent (m, time);)
{
if (m.isNoteOn() && m.getNoteNumber() < 58 ) // reset the array position and play first chord
{
chordsPosition = 0;
// for notes in current chord
for ( int i = 0; i < (chords[chordsPosition]).size() - 1 ; i++){
int NewNote = chords[chordsPosition][i];
m = MidiMessage::noteOn(m.getChannel(), NewNote , m.getVelocity());
midiBuffer.addEvent (m, time);
}
}
else if (m.isNoteOff() && m.getNoteNumber() < 58 )
{
// send note offs for first chord in array
// for notes in current chord
for ( int i = 0; i < (chords[chordsPosition]).size() - 1 ; i++){
int NewNote = chords[chordsPosition][i];
m = MidiMessage::noteOff(m.getChannel(), NewNote , m.getVelocity());
midiBuffer.addEvent (m, time);
}
}
else if (m.isNoteOn() && m.getNoteNumber() == 59 )
{
// move chord pointer back one space if it is not at zero
if (chordsPosition > 0)
{ chordsPosition -= 1 ;}
for ( int i = 0; i < (chords[chordsPosition]).size() - 1 ; i++){
int NewNote = chords[chordsPosition][i];
m = MidiMessage::noteOn(m.getChannel(), NewNote , m.getVelocity());
midiBuffer.addEvent (m, time);
}
}
else if (m.isNoteOff() && m.getNoteNumber() == 59)
{
// send note offs for first chord in array
// for notes in current chord
for ( int i = 0; i < (chords[chordsPosition]).size() - 1 ; i++){
int NewNote = chords[chordsPosition][i];
m = MidiMessage::noteOff(m.getChannel(), NewNote , m.getVelocity());
midiBuffer.addEvent (m, time);
}
}
How should I do this ?
When I was just dealing with single notes I used this
midiMessages.swapWith (processedMidi);
Can I put the those noteon() routines in a function ?
Where would I declare it ?
Can I just declare a global function(s) with that stuff in it under the variables ?
Sorry 2 questions in one and still a beginner at JUCE !
Sean