本文整理汇总了C++中MidiMessage类的典型用法代码示例。如果您正苦于以下问题:C++ MidiMessage类的具体用法?C++ MidiMessage怎么用?C++ MidiMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MidiMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleEvent
void SpikeDisplayNode::handleEvent(int eventType, MidiMessage& event, int samplePosition)
{
//std::cout << "Received event of type " << eventType << std::endl;
if (eventType == SPIKE)
{
const uint8_t* dataptr = event.getRawData();
int bufferSize = event.getRawDataSize();
if (bufferSize > 0)
{
SpikeObject newSpike;
bool isValid = unpackSpike(&newSpike, dataptr, bufferSize);
if (isValid)
{
int electrodeNum = newSpike.source;
Electrode& e = electrodes.getReference(electrodeNum);
// std::cout << electrodeNum << std::endl;
bool aboveThreshold = false;
// update threshold / check threshold
for (int i = 0; i < e.numChannels; i++)
{
e.detectorThresholds.set(i, float(newSpike.threshold[i])); // / float(newSpike.gain[i]));
aboveThreshold = aboveThreshold | checkThreshold(i, e.displayThresholds[i], newSpike);
}
if (aboveThreshold)
{
// add to buffer
if (e.currentSpikeIndex < displayBufferSize)
{
// std::cout << "Adding spike " << e.currentSpikeIndex + 1 << std::endl;
e.mostRecentSpikes.set(e.currentSpikeIndex, newSpike);
e.currentSpikeIndex++;
}
// save spike
if (isRecording)
{
CoreServices::RecordNode::writeSpike(newSpike,e.recordIndex);
}
}
}
}
}
}
示例2: sendMessageNow
void sendMessageNow (const MidiMessage& message)
{
if (message.getRawDataSize() > maxEventSize)
{
maxEventSize = message.getRawDataSize();
snd_midi_event_free (midiParser);
snd_midi_event_new (maxEventSize, &midiParser);
}
snd_seq_event_t event;
snd_seq_ev_clear (&event);
snd_midi_event_encode (midiParser,
message.getRawData(),
message.getRawDataSize(),
&event);
snd_midi_event_reset_encode (midiParser);
snd_seq_ev_set_source (&event, 0);
snd_seq_ev_set_subs (&event);
snd_seq_ev_set_direct (&event);
snd_seq_event_output (seqHandle, &event);
snd_seq_drain_output (seqHandle);
}
示例3: getMidiValue
const String getMidiValue(const MidiMessage &m)
{
if (m.isAftertouch())
{
return (String::formatted (" Val:[%4d]", m.getAfterTouchValue()));
}
if (m.isController())
{
return (String::formatted (" Val:[%4d]", m.getControllerValue()));
}
if (m.isNoteOnOrOff())
{
return (String::formatted (" Val:[%4d]", m.getVelocity()));
}
if (m.isPitchWheel())
{
return (String::formatted (" Val:[%4d]", m.getPitchWheelValue()));
}
if (m.isChannelPressure())
{
return (String::formatted (" Val:[%4d]", m.getChannelPressureValue()));
}
return (" Val:[----]");
}
示例4: main
int main(int argc, char* argv[]) {
int incount = MidiInPort::getNumPorts();
int outcount = MidiOutPort::getNumPorts();
Array<ArrayInt> connections;
connections.setSize(incount);
int i, j;
for (i=0; i<incount; i++) {
connections[i].setSize(outcount);
connections[i].setAll(1);
}
// temporary connections for now:
// connections[0][2] = 0;
// connections[1][2] = 0;
cout << "There are " << incount << " MIDI inputs" << endl;
cout << "and " << outcount << " MIDI outputs" << endl;
MidiMessage message;
Array<MidiInput> midiins;
for (i=0; i<incount; i++) {
midiins[i].setPort(i);
midiins[i].open();
}
Array<MidiOutPort> midiouts;
midiouts.setSize(outcount);
for (i=0; i<outcount; i++) {
midiouts[i].setPort(i);
midiouts[i].open();
cout << "opened MIDI output number " << i << endl;
}
connections[0][3] = 0;
displayPatchBay(connections);
int done = 0;
while (!done) {
for (i=0; i<incount; i++) {
while (midiins[i].getCount() > 0) {
message = midiins[i].extract();
if (message.p1() == A0) {
done = 1;
}
cout << "[" << i << ":";
for (j=0; j<outcount; j++) {
if (connections[i][j]) {
cout << j << " ";
sendData(message, midiouts[j], midiins[i]);
}
}
cout << "]" << flush;
}
}
}
return 0;
}
示例5: throw
void MIDIMostRecentNoteInternal::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message) throw()
{
if(port_ != 0 && port_ != source) return;
if(message.isForChannel(midiChannel_) == false) return;
if(message.isNoteOn() == false) return;
setNormalisedValue(message.getNoteNumber() / 127.f);
}
示例6: getDataFromResponse
const MemoryBlock CtrlrMIDITransaction::getDataFromResponse(const MidiMessage &messageToExtractFrom)
{
MemoryBlock returnData;
MemoryBlock temp(messageToExtractFrom.getRawData(), messageToExtractFrom.getRawDataSize());
returnData.copyFrom (temp.getData(), getResponsePrefixLength(), getResponseDataLength());
return (returnData);
}
示例7: sendMessageNow
void MidiOutput::sendMessageNow (const MidiMessage& message)
{
#if JUCE_IOS
const MIDITimeStamp timeStamp = mach_absolute_time();
#else
const MIDITimeStamp timeStamp = AudioGetCurrentHostTime();
#endif
HeapBlock<MIDIPacketList> allocatedPackets;
MIDIPacketList stackPacket;
MIDIPacketList* packetToSend = &stackPacket;
const size_t dataSize = (size_t) message.getRawDataSize();
if (message.isSysEx())
{
const int maxPacketSize = 256;
int pos = 0, bytesLeft = (int) dataSize;
const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
allocatedPackets.malloc ((size_t) (32 * (size_t) numPackets + dataSize), 1);
packetToSend = allocatedPackets;
packetToSend->numPackets = (UInt32) numPackets;
MIDIPacket* p = packetToSend->packet;
for (int i = 0; i < numPackets; ++i)
{
p->timeStamp = timeStamp;
p->length = (UInt16) jmin (maxPacketSize, bytesLeft);
memcpy (p->data, message.getRawData() + pos, p->length);
pos += p->length;
bytesLeft -= p->length;
p = MIDIPacketNext (p);
}
}
else if (dataSize < 65536) // max packet size
{
const size_t stackCapacity = sizeof (stackPacket.packet->data);
if (dataSize > stackCapacity)
{
allocatedPackets.malloc ((sizeof (MIDIPacketList) - stackCapacity) + dataSize, 1);
packetToSend = allocatedPackets;
}
packetToSend->numPackets = 1;
MIDIPacket& p = *(packetToSend->packet);
p.timeStamp = timeStamp;
p.length = (UInt16) dataSize;
memcpy (p.data, message.getRawData(), dataSize);
}
else
{
jassertfalse; // packet too large to send!
return;
}
static_cast<CoreMidiHelpers::MidiPortAndEndpoint*> (internal)->send (packetToSend);
}
示例8: sendData
void sendData(MidiMessage& m, MidiOutPort& output,
MidiInput& input) {
int count = m.getParameterCount();
if (count >= 0 && count <= 2) {
if (count >= 0) output.rawsend(m.p0());
if (count >= 1) output.rawsend(m.p0(), m.p1());
if (count >= 2) output.rawsend(m.p0(), m.p1(), m.p2());
}
}
示例9: getMidiChannel
const String getMidiChannel(const MidiMessage &m)
{
if (m.getChannel() > 0)
{
return (String::formatted (" Ch:[%2d]", m.getChannel()));
}
return (" Ch:[--]");
}
示例10: sendCurrentNoteToBuffer
void Loop::sendCurrentNoteToBuffer(MidiBuffer& buffer, int sample_number, int velocity)
{
MidiMessage m = this->getEventPointer(currentIndex)->message;
//playingNote[m.getNoteNumber()][m.getChannel()-1][0] = jlimit(0,127,m.getNoteNumber()+getTransposition());
m.setNoteNumber(jlimit(0,127,m.getNoteNumber()+getTransposition()));
m.setVelocity((((float)velocity*midiScaler * velocitySensitivity) + (1.f-velocitySensitivity)));
if (outChannel>0) m.setChannel(outChannel);
buffer.addEvent(m,sample_number);
indexOfLastNoteOn=currentIndex;
}
示例11: handleIncomingMidiMessage
void MidiPedalCallback::handleIncomingMidiMessage (MidiInput *source, const MidiMessage &message)
{
if (message.isController()) {
int x = message.getControllerNumber();
bool button_check = is_item_in_list(x, button_check_list);
if (button_check == true) {
buttonPressed = x;
sendActionMessage("To audio_midi from midiPedalCallback: grab buttonPressed");
}
}
}
示例12:
StringTS::StringTS(MidiMessage& event)
{
const uint8* dataptr = event.getRawData();
int bufferSize = event.getRawDataSize();
len = bufferSize - 20;
str = new uint8[len];
memcpy(str, dataptr+6, len);
memcpy(×tamp, dataptr +6+ len, 8);
}
示例13: processMidiCommand
void processMidiCommand(MidiMessage& message) {
if (message.p0() != 0x90 || message.p2() == 0) {
return;
}
switch (message.p1()) {
case 60: // Middle C = beat
keyboardchar(' ');
break;
case 61: // C# = amplitude control
{
double amp = performance.getAmp();
amp = amp * message.p2() / 64;
if (amp < 0) {
amp = 0;
} else if (amp > 127) {
amp = 127;
}
performance.setAmp((int)amp);
}
break;
case 71: // B = 1 beat tempo follow
keyboardchar('1');
break;
case 72: // C = 2 beat tempo follow
keyboardchar('2');
break;
case 73: // C# = 3 beat tempo follow
keyboardchar('3');
break;
case 74: // D = 4 beat tempo follow
keyboardchar('4');
break;
case 79: // G = constant tempo follow
keyboardchar('9');
break;
case 80: // G# = automatic
keyboardchar('0');
break;
case 62: // amplitude decrease
keyboardchar('[');
break;
case 63: // amplitude increase
keyboardchar(']');
break;
case 64: // tempo decrease
keyboardchar('-');
break;
case 65: // tempo increase
keyboardchar('=');
break;
}
}
示例14: handleIncomingMidiMessage
void MIDIInputDevice::handleIncomingMidiMessage(MidiInput * source, const MidiMessage & message)
{
if (source != device)
{
DBG("different device");
return;
}
if (message.isNoteOn()) inputListeners.call(&MIDIInputListener::noteOnReceived, message.getChannel(), message.getNoteNumber(), message.getVelocity());
else if(message.isNoteOff()) inputListeners.call(&MIDIInputListener::noteOffReceived, message.getChannel(), message.getNoteNumber(), 0); //force note off to velocity 0
else if(message.isController()) inputListeners.call(&MIDIInputListener::controlChangeReceived, message.getChannel(), message.getControllerNumber(), message.getControllerValue());
else if(message.isSysEx()) inputListeners.call(&MIDIInputListener::sysExReceived, message);
}
示例15: SendMessageAndWaitReply
bool MidiMessageBox::SendMessageAndWaitReply(MidiOutput *out, MidiMessage &msg, int msec)
{
if (!out)
return false;
Logger::getCurrentLogger()->writeToLog("midiout: send message and wait reply");
string dbg = ToHexString(msg.getRawData(), msg.getRawDataSize());
Logger::getCurrentLogger()->writeToLog(dbg);
std::unique_lock<std::mutex> lck(_mutex);
out->sendMessageNow(msg);
return std::cv_status::no_timeout == _reply_cv.wait_for(lck, std::chrono::milliseconds(msec));
}