本文整理汇总了C++中MidiMessage::getChannel方法的典型用法代码示例。如果您正苦于以下问题:C++ MidiMessage::getChannel方法的具体用法?C++ MidiMessage::getChannel怎么用?C++ MidiMessage::getChannel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MidiMessage
的用法示例。
在下文中一共展示了MidiMessage::getChannel方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleMidiEvent
void Synthesiser::handleMidiEvent (const MidiMessage& m)
{
const int channel = m.getChannel();
if (m.isNoteOn())
{
noteOn (channel, m.getNoteNumber(), m.getFloatVelocity());
}
else if (m.isNoteOff())
{
noteOff (channel, m.getNoteNumber(), m.getFloatVelocity(), true);
}
else if (m.isAllNotesOff() || m.isAllSoundOff())
{
allNotesOff (channel, true);
}
else if (m.isPitchWheel())
{
const int wheelPos = m.getPitchWheelValue();
lastPitchWheelValues [channel - 1] = wheelPos;
handlePitchWheel (channel, wheelPos);
}
else if (m.isAftertouch())
{
handleAftertouch (channel, m.getNoteNumber(), m.getAfterTouchValue());
}
else if (m.isChannelPressure())
{
handleChannelPressure (channel, m.getChannelPressureValue());
}
else if (m.isController())
{
handleController (channel, m.getControllerNumber(), m.getControllerValue());
}
else if (m.isProgramChange())
{
handleProgramChange (channel, m.getProgramChangeNumber());
}
}
示例2: runAudio
void Gear_Slider::runAudio()
{
bool accept_midi = _settings.get(Gear_Slider::SETTING_ACCEPTMIDI)->valueBool();
if(accept_midi)
{
MidiMessage* msg;
std::vector<MidiMessage*> messages = MidiEngine::getInstance().getMessages();
if(messages.size())
{
int channel = _settings.get(Gear_Slider::SETTING_MIDICHANNEL)->valueInt();
int controller = _settings.get(Gear_Slider::SETTING_MIDICONTROLLER)->valueInt();
// we only consider the LAST controller value
float low = _settings.get(Gear_Slider::SETTING_LOWERBOUND)->valueFloat();
float hi = _settings.get(Gear_Slider::SETTING_HIGHERBOUND)->valueFloat();
float lastValue = -1,lastStamp;
for(unsigned int i=0;i<messages.size();i++)
{
msg = messages[i];
if(msg->isControllerChange() && msg->getChannel()==channel && msg->getController()==controller)
{
lastValue = (float)msg->getControllerValue() / 127;
lastStamp = msg->getStamp();
}
}
if(lastValue!=-1)
{
//std::cout<<"set Value !! :"<<lastValue<<" "<<lastStamp<<std::endl;
setValue(low + (hi-low)*lastValue);
// can't call this from here since we're in a different thread than the GUI
//getGearGui()->reDraw();
}
}
}
}
示例3: processBlock
//==============================================================================
void MidiSequencePlugin::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
MidiSequencePluginBase::processBlock(buffer, midiMessages);
MidiMessageSequence sourceMidi = *midiSequence;
std::vector<int> doneTheseControllers;
if (transport->isPlaying () && getBoolValue(PROP_SEQENABLED, true))
{
const int blockSize = buffer.getNumSamples ();
MidiBuffer* midiBuffer = midiBuffers.getUnchecked (0);
const int frameCounter = transport->getPositionInFrames ();
const int framesPerBeat = transport->getFramesPerBeat ();
const int nextBlockFrameNumber = frameCounter + blockSize;
const int seqIndex = getLoopRepeatIndex();
const double beatCount = getLoopBeatPosition();
const double frameLenBeatCount = (nextBlockFrameNumber - frameCounter) / (double)framesPerBeat;
double frameEndBeatCount = beatCount + frameLenBeatCount;
if (frameEndBeatCount > getLengthInBeats())
frameEndBeatCount -= getLengthInBeats();
// loop for each controller we need to interpolate
MidiMessage* lastCtrlEvent = NULL;
do
{
lastCtrlEvent = NULL;
// hunt for a controller event before now
int i;
for (i = 0; i < sourceMidi.getNumEvents (); i++)
{
int timeStampInSeq = roundFloatToInt (sourceMidi.getEventTime (i) * framesPerBeat);
int timeStamp = timeStampInSeq + (seqIndex * getLengthInBeats() * framesPerBeat);
MidiMessage* midiMessage = &sourceMidi.getEventPointer (i)->message;
if (timeStamp >= nextBlockFrameNumber || !midiMessage)
break; // event is after now, leave
//if (midiMessage->isController() && (std::find(doneTheseControllers.begin(), doneTheseControllers.end(), midiMessage->getControllerNumber()) == doneTheseControllers.end()))
// lastCtrlEvent = midiMessage;
}
// hunt for a matching event after that one
if (lastCtrlEvent)
{
// store the controller number so we know which controllers we've done
doneTheseControllers.push_back(lastCtrlEvent->getControllerNumber());
MidiMessage* nextCtrlEvent = NULL;
for (; i < sourceMidi.getNumEvents (); i++)
{
MidiMessage* midiMessage = &sourceMidi.getEventPointer (i)->message;
if (midiMessage->isController() && midiMessage->getControllerNumber() == lastCtrlEvent->getControllerNumber())
{
nextCtrlEvent = midiMessage;
break;
}
}
// render an interpolated event!...
if (nextCtrlEvent)
{
double bt = nextCtrlEvent->getTimeStamp();
double at = lastCtrlEvent->getTimeStamp();
double deltaBeats = bt - at;
int a = lastCtrlEvent->getControllerValue();
int b = nextCtrlEvent->getControllerValue();
double now = beatCount + (frameEndBeatCount - beatCount) / 2.0;
double interpRemainBeats = deltaBeats - (now - at);
if (deltaBeats > 0)
{
double nextPart = interpRemainBeats / deltaBeats;
nextPart = 1 - nextPart;
double interpdVal = a + nextPart * (b - a);
MidiMessage interpy = MidiMessage::controllerEvent(lastCtrlEvent->getChannel(), lastCtrlEvent->getControllerNumber(), static_cast<int>(interpdVal));
midiBuffer->addEvent (interpy, (nextBlockFrameNumber - frameCounter) / 2);
}
else
{
DBG ("Negative delta beats when rendering automation!!");
}
}
}
// now we also need to do that again if there are multiple events per frame AND we are interpolating multiple times per frame
// (at the moment only interpolating once per audio frame)
} while (lastCtrlEvent != NULL);
}
}
示例4: runVideo
void Gear_PushButton::runVideo()
{
bool accept_midi = _settings.get(Gear_PushButton::SETTING_ACCEPTMIDI)->valueBool();
if(accept_midi)
{
bool noteOff;
MidiMessage* msg;
std::vector<MidiMessage*> messages = MidiEngine::getInstance().getMessages();
if(messages.size())
{
int channel = _settings.get(Gear_PushButton::SETTING_MIDICHANNEL)->valueInt();
int Note = _settings.get(Gear_PushButton::SETTING_MIDINOTE)->valueInt();
// we only consider the LAST Note value
float on =_settings.get(Gear_PushButton::SETTING_ONVALUE)->valueFloat();
float off =_settings.get(Gear_PushButton::SETTING_OFFVALUE)->valueFloat();
float highValue = -1,lastStamp;
noteOff=false;
for(int i=0;i<messages.size();i++)
{
msg = messages[i];
if(msg->isNoteEvent() && msg->getChannel()==channel && msg->getNote()==Note)
{
std::cerr<<"have event!!!!!!!"<<std::endl;
if(msg->getNoteValue()==0)
noteOff=true;
else
{
noteOff=false;
highValue = (float)msg->getNoteValue() / 127;
}
lastStamp = msg->getStamp();
}
}
if(highValue!=-1)
{
//std::cout<<"set Value !! :"<<lastValue<<" "<<lastStamp<<std::endl;
setState(ON);
// can't call this from here since we're in a different thread than the GUI
//getGearGui()->reDraw();
}
}
if (noteOff)
{
_havePendingRelease=true;
}
}
// keyboard part
if(_settings.get(Gear_PushButton::SETTING_ONESHOT)->valueBool() && _lastWasOn)
setState(OFF);
if(_VALUE_OUT->type()->value()==_settings.get(Gear_PushButton::SETTING_ONVALUE)->valueFloat())
_lastWasOn=true;
else
_lastWasOn=false;
_haveUnconsumedClick=false;
if(_havePendingRelease)
setState(OFF);
}
示例5: timerCallback
//==============================================================================
void MidiMonitorEditor::timerCallback ()
{
MidiBuffer tmpBuffer;
int hours, minutes, seconds, frames;
MidiMessage::SmpteTimecodeType timeCode;
MidiMessageCollector* collector = owner->getMessageCollector ();
collector->removeNextBlockOfMessages (tmpBuffer, 1024);
if (! tmpBuffer.isEmpty())
{
String midiLine;
int samplePos = 0;
MidiMessage msg (0xf4, 0.0);
MidiBuffer::Iterator eventIterator (tmpBuffer);
while (eventIterator.getNextEvent (msg, samplePos))
{
midiLine.printf (T("[CH: %d] "), msg.getChannel());
if (msg.isNoteOnOrOff ())
{
midiLine += MidiMessage::getMidiNoteName (msg.getNoteNumber(),
true, true, 0);
midiLine += " ";
midiLine += String ((int) msg.getVelocity ());
if (msg.isNoteOn())
{
midiLine += " ON";
}
else
{
midiLine += " OFF";
}
}
else if (msg.isAllNotesOff())
{
midiLine += "ALL NOTES OFF";
}
else if (msg.isAllSoundOff())
{
midiLine += "ALL SOUND OFF";
}
else if (msg.isPitchWheel())
{
midiLine += "PITCHWEEL: ";
midiLine += String (msg.getPitchWheelValue());
}
else if (msg.isAftertouch())
{
midiLine += "AFTERTOUCH: ";
midiLine += String (msg.getAfterTouchValue());
}
else if (msg.isChannelPressure())
{
midiLine += "CHANNELPRESSURE: ";
midiLine += String (msg.getChannelPressureValue());
}
else if (msg.isSysEx())
{
midiLine += "SYSEX: ";
midiLine += String (msg.getSysExDataSize());
midiLine += " bytes";
}
else if (msg.isProgramChange())
{
midiLine += "PROGRAM CHANGE: ";
midiLine += String (msg.getProgramChangeNumber());
midiLine += " (";
midiLine += MidiMessage::getGMInstrumentName (msg.getProgramChangeNumber());
midiLine += ")";
}
else if (msg.isController())
{
midiLine += "CC: #";
midiLine += String (msg.getControllerNumber());
midiLine += " (";
midiLine += MidiMessage::getControllerName (msg.getControllerNumber());
midiLine += ") = ";
midiLine += String (msg.getControllerValue());
}
else if (msg.isTimeSignatureMetaEvent ())
{
int newNumerator, newDenominator;
msg.getTimeSignatureInfo (newNumerator, newDenominator);
midiLine += "TIME SIGNATURE: ";
midiLine += String (newNumerator);
midiLine += " / ";
midiLine += String (newDenominator);
}
else if (msg.isTempoMetaEvent ())
{
midiLine += "TEMPO: ";
midiLine += String (msg.getTempoSecondsPerQuarterNote ());
//midiLine += " ";
//midiLine += String (msg.getTempoMetaEventTickLength (ticksPerQuarterNote));
//.........这里部分代码省略.........
示例6: recordPattern
void PatternRecording::recordPattern(MidiBuffer &midiMessages, const int &numSamples)
{
// if we are recording the pattern, just rip the
// MIDI messages from the incoming buffer
if (isPatternRecording)
{
// get the iterator for the incoming buffer
// so we can check through the messages
MidiBuffer::Iterator i(midiMessages);
MidiMessage message (0xf4, 0.0);
int time;
// if we are still during the precount, do nothing
if (patternPrecountPosition > numSamples)
patternPrecountPosition -= numSamples;
// if the precount finishes during this buffer
else if (patternPrecountPosition > 0)
{
// TODO: overdub could be option here?
midiPattern.clear();
const int numSamplesToAdd = numSamples - patternPrecountPosition;
// DBG("#1 recording " << numSamplesToAdd << " of midi, pos: " << patternPrecountPosition);
// get messages from the main MIDI message queue
while(i.getNextEvent(message, time))
{
// and add them if they occur after the precount runs out
if (time > patternPrecountPosition)
{
midiPattern.addEvent(message, time - patternPrecountPosition);
// store noteOffs to fire at end
if (message.isNoteOn())
{
MidiMessage tempNoteOff = MidiMessage::noteOff(message.getChannel(), message.getNoteNumber(), message.getVelocity());
noteOffs.addEvent(tempNoteOff, 0);
}
}
}
// the precount has finished
patternPrecountPosition = 0;
// we are now numSamplesToAdd into the buffer
patternPosition = numSamplesToAdd;
}
else
{
// if we are during recording (and not near the end), just
// add the current input into the record buffer
if (numSamples + patternPosition < patternLengthInSamples)
{
// DBG("#2 recording " << numSamples << " of midi, pos: " << patternPosition);
// get messages from the main MIDI message queue
while(i.getNextEvent(message, time))
{
midiPattern.addEvent(message, time + patternPosition);
// store noteOffs to fire at end
if (message.isNoteOn())
{
MidiMessage tempNoteOff = MidiMessage::noteOff(message.getChannel(), message.getNoteNumber(), message.getVelocity());
noteOffs.addEvent(tempNoteOff, 0);
}
}
//midiPattern.addEvents(midiMessages, 0, numSamples, -patternPosition);
patternPosition += numSamples;
}
// otherwise we are finishing up
else
{
const int numSamplesLeftToRecord = patternLengthInSamples - patternPosition;
// add remaining messages from the main MIDI message queue
while(i.getNextEvent(message, time))
{
if (time < numSamplesLeftToRecord)
midiPattern.addEvent(message, time + patternPosition);
// store noteOffs to fire at end
if (message.isNoteOn())
{
MidiMessage tempNoteOff = MidiMessage::noteOff(message.getChannel(), message.getNoteNumber(), message.getVelocity());
noteOffs.addEvent(tempNoteOff, 0);
}
}
// add the note offs to clear any "phantom notes"
midiPattern.addEvents(noteOffs, 0, 1, patternLengthInSamples - 1);
// we are no longer recording
isPatternRecording = false;
// if we finish recording, let any listeners know
// so they can redraw representations of the pattern
sendChangeMessage();
//.........这里部分代码省略.........
示例7: processBlock
void MiditoOscAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
static float cv[8], shiftcv[8];
static bool _calibMode;
MidiBuffer processedMidi;
MidiMessage m;
int time;
char oscBuffer[IP_MTU_SIZE];
osc::OutboundPacketStream p(oscBuffer, IP_MTU_SIZE);
if (calibMode) // Calibration Mode A440Hz(MIDI number 69)
{
p << osc::BeginBundleImmediate
<< osc::BeginMessage( "/fader1" )
<< calibMap[69] << osc::EndMessage
<< osc::BeginMessage( "/fader2" )
<< calibMap[69] << osc::EndMessage
<< osc::BeginMessage( "/fader3" )
<< calibMap[69] << osc::EndMessage
<< osc::BeginMessage( "/fader4" )
<< calibMap[69] << osc::EndMessage
<< osc::BeginMessage( "/fader5" )
<< calibMap[69] << osc::EndMessage
<< osc::BeginMessage( "/fader6" )
<< calibMap[69] << osc::EndMessage
<< osc::BeginMessage( "/fader7" )
<< calibMap[69] << osc::EndMessage
<< osc::BeginMessage( "/fader8" )
<< calibMap[69] << osc::EndMessage
<< osc::BeginMessage( "/gate1" )
<< 1 << osc::EndMessage
<< osc::BeginMessage( "/gate2" )
<< 1 << osc::EndMessage
<< osc::EndBundle;
sendOSCData(p);
_calibMode = true;
return;
} else {
if (_calibMode)
{
p << osc::BeginBundleImmediate
<< osc::BeginMessage( "/gate1" )
<< 0 << osc::EndMessage
<< osc::BeginMessage( "/gate2" )
<< 0 << osc::EndMessage
<< osc::EndBundle;
sendOSCData(p);
_calibMode = false;
}
}
for (MidiBuffer::Iterator i (midiMessages); i.getNextEvent (m, time);)
{
p.Clear();
usleep(30);
if (m.isNoteOn())
{
if (monoMode) // mono Mode
{
uint32_t midiCh = m.getChannel();
if (midiCh == 0 || midiCh > 7)
{
midiCh = 1;
}
cv[midiCh - 1] = calibMap[m.getNoteNumber()];
switch (midiCh)
{
case 1:
p << osc::BeginMessage("/fader1")
<< cv[0] << osc::EndMessage;
break;
case 2:
p << osc::BeginMessage("/fader2")
<< cv[1] << osc::EndMessage;
break;
case 3:
p << osc::BeginMessage("/fader3")
<< cv[2] << osc::EndMessage;
break;
case 4:
p << osc::BeginMessage("/fader4")
<< cv[3] << osc::EndMessage;
break;
//.........这里部分代码省略.........
示例8: handleIncomingMidiMessage
void MIDIReceiver::handleIncomingMidiMessage (MidiInput *source, const MidiMessage &message)
{
DBG("midi in");
// is this midi input source enabled
if(_MidiDeviceManager->isMidiInputEnabled(source->getName()))
{
DBG(source->getName());
if(message.isController() && _MidiDeviceManager->isCcEnabled(source->getName(), true)
&& appProperties->getUserSettings()->getIntValue("midiInputChannel") == message.getChannel())
{
DBG(message.getControllerNumber() );
// reference counted Signal ( string command, string origin )
Signal::SignalP ledStateSignal = new Signal("SEND_OSC", "RCV_MIDI");
ledStateSignal->addStringArg("/nomestate/grid/led/set");
// get the x position: LED bumber % 8
ledStateSignal->addIntArg(message.getControllerNumber() % 8);
// get the y position: LED number / 8
ledStateSignal->addIntArg(message.getControllerNumber() / 8);
// get the LED state: toggleState
int ledState;
if (message.getControllerValue() > 0) {
ledState = 1;
}
ledStateSignal->addIntArg(ledState);
_mCenter->handleSignal(*ledStateSignal);
}
else if (message.isNoteOn() && _MidiDeviceManager->isNoteEnabled(source->getName(), true)
&& appProperties->getUserSettings()->getIntValue("midiInputChannel") == message.getChannel())
{
// lets set the color based off MIDI note Velocity
int MIDIVelocity = message.getVelocity();
int r = 0;
int g = 0;
int b = 0;
if (MIDIVelocity > 0) {
// red
if (MIDIVelocity <= 22)
{
r = 127;
}
// yellow
else if (MIDIVelocity <= 43)
{
r = 127;
g = 127;
}
// green
else if (MIDIVelocity <= 64)
{
g = 127;
}
// teal
else if (MIDIVelocity <= 85)
{
g = 127;
b = 127;
}
// blue
else if (MIDIVelocity <= 106)
{
b = 127;
}
// purple
else
{
b = 127;
r = 127;
}
}
// reference counted Signal ( string command, string origin )
Signal::SignalP ledColourSignal = new Signal("SEND_OSC", "RCV_MIDI");
ledColourSignal->addStringArg("/nomestate/grid/led/color");
// get the x position: LED bumber % 8
ledColourSignal->addIntArg(message.getNoteNumber() % 8);
// get the y position: LED number / 8
ledColourSignal->addIntArg(message.getNoteNumber() / 8);
// get the LED RED:
ledColourSignal->addIntArg(r);
// get the LED GREEN:
ledColourSignal->addIntArg(g);
// get the LED BLUE:
ledColourSignal->addIntArg(b);
_mCenter->handleSignal(*ledColourSignal);
// reference counted Signal ( string command, string origin )
Signal::SignalP ledStateSignal = new Signal("SEND_OSC", "RCV_MIDI");
ledStateSignal->addStringArg("/nomestate/grid/led/set");
// get the x position: LED bumber % 8
ledStateSignal->addIntArg(message.getNoteNumber() % 8);
//.........这里部分代码省略.........
示例9: processBlock
void InstanceProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
for(int i = getTotalNumInputChannels(); i < getTotalNumOutputChannels(); ++i)
{
buffer.clear(i, 0, buffer.getNumSamples());
}
bool infos = false;
AudioPlayHead* playhead = getPlayHead();
if(playhead && m_patch_tie)
{
infos = playhead->getCurrentPosition(m_playinfos);
}
lock();
{
m_midi.clear();
if(infos)
{
m_playing_list.setFloat(0, m_playinfos.isPlaying);
m_playing_list.setFloat(1, m_playinfos.timeInSeconds);
sendMessageAnything(m_patch_tie, s_playing, m_playing_list);
m_measure_list.setFloat(0, m_playinfos.bpm);
m_measure_list.setFloat(1, m_playinfos.timeSigNumerator);
m_measure_list.setFloat(2, m_playinfos.timeSigDenominator);
m_measure_list.setFloat(3, m_playinfos.ppqPosition);
m_measure_list.setFloat(4, m_playinfos.ppqPositionOfLastBarStart);
sendMessageAnything(m_patch_tie, s_measure, m_measure_list);
}
for(size_t i = 0; i < m_parameters.size() && m_parameters[i].isValid(); ++i)
{
sendMessageFloat(m_parameters[i].getTie(), m_parameters[i].getValueNonNormalized());
}
MidiMessage message;
MidiBuffer::Iterator it(midiMessages);
int position = midiMessages.getFirstEventTime();
while(it.getNextEvent(message, position))
{
if(message.isNoteOnOrOff())
{
sendMidiNote(message.getChannel(), message.getNoteNumber(), message.getVelocity());
}
else if(message.isController())
{
sendMidiControlChange(message.getChannel(), message.getControllerNumber(), message.getControllerValue());
}
else if(message.isPitchWheel())
{
sendMidiPitchBend(message.getChannel(), message.getPitchWheelValue());
}
else if(message.isChannelPressure())
{
sendMidiAfterTouch(message.getChannel(), message.getChannelPressureValue());
}
else if(message.isAftertouch())
{
sendMidiPolyAfterTouch(message.getChannel(), message.getNoteNumber(), message.getAfterTouchValue());
}
else if(message.isProgramChange())
{
sendMidiProgramChange(message.getChannel(), message.getProgramChangeNumber());
}
}
}
midiMessages.clear();
performDsp(buffer.getNumSamples(),
getTotalNumInputChannels(), buffer.getArrayOfReadPointers(),
getTotalNumOutputChannels(), buffer.getArrayOfWritePointers());
midiMessages.swapWith(m_midi);
unlock();
}