Exemplo n.º 1
0
String MidiMessage::getDescription() const
{
    if (isNoteOn())           return "Note on "  + MidiMessage::getMidiNoteName (getNoteNumber(), true, true, 3) + " Velocity " + String (getVelocity()) + " Channel " + String (getChannel());
    if (isNoteOff())          return "Note off " + MidiMessage::getMidiNoteName (getNoteNumber(), true, true, 3) + " Velocity " + String (getVelocity()) + " Channel " + String (getChannel());
    if (isProgramChange())    return "Program change " + String (getProgramChangeNumber()) + " Channel " + String (getChannel());
    if (isPitchWheel())       return "Pitch wheel " + String (getPitchWheelValue()) + " Channel " + String (getChannel());
    if (isAftertouch())       return "Aftertouch " + MidiMessage::getMidiNoteName (getNoteNumber(), true, true, 3) +  ": " + String (getAfterTouchValue()) + " Channel " + String (getChannel());
    if (isChannelPressure())  return "Channel pressure " + String (getChannelPressureValue()) + " Channel " + String (getChannel());
    if (isAllNotesOff())      return "All notes off Channel " + String (getChannel());
    if (isAllSoundOff())      return "All sound off Channel " + String (getChannel());
    if (isMetaEvent())        return "Meta event";

    if (isController())
    {
        String name (MidiMessage::getControllerName (getControllerNumber()));

        if (name.isEmpty())
            name = String (getControllerNumber());

        return "Controller " + name + ": " + String (getControllerValue()) + " Channel " + String (getChannel());
    }

    return String::toHexString (getRawData(), getRawDataSize());
}
Exemplo n.º 2
0
void MidiScaleChanger::processMidiEvents(VstMidiEventVec *inputs, VstMidiEventVec *outputs, VstInt32 sampleFrames)
{
	const int nchannel = FLOAT_TO_CHANNEL(fAltChannel);

    for (unsigned int i=0;i<inputs[0].size();i++) {
 		VstMidiEvent tomod = inputs[0][i];
        const int status     = tomod.midiData[0] & 0xf0;  // scraping  channel
        const int channel    = tomod.midiData[0] & 0x0f;  // isolating channel (0-15)
        const int data1      = tomod.midiData[1] & 0x7f;
        bool discard = false;
        int tchannel = FLOAT_TO_CHANNEL(fChannel);
        if (tchannel==-1) tchannel = channel;

		if (isNoteOn(tomod)) {
			int n = data1%12;
			if (notetable[n]==-13) {
				if (nchannel==-1) {
					discard = true;
					transposed[data1][channel] = -999;
				}
				else {
					tomod.midiData[0] = MIDI_NOTEON | nchannel;
				}
			}
			else
			{
				int newdata1 = root + data1 + notetable[n];
				if (newdata1>127 || newdata1<0)
				{
					if (wrap) {
						newdata1 = midiNoteWrap(newdata1);
						transposed[data1][channel] = newdata1;
						tomod.midiData[0] = MIDI_NOTEON | tchannel;
						tomod.midiData[1] = newdata1;
					}
					else {
						discard = true;
						transposed[data1][channel] = -999;
					}
				}
				else
				{
					transposed[data1][channel] = newdata1;
					tomod.midiData[0] = MIDI_NOTEON | tchannel;
					tomod.midiData[1] = (char)newdata1;
				}
			}
			noteOnChannel[data1][channel] = tomod.midiData[0] & 0x0f;
		}
        else if (isNoteOff(tomod)) {
            // always transpose noteoff by the same amount that the noteon was transposed by (and send on the same channel)
            if (transposed[data1][channel]==-999) 
				discard = true;
            else
            {
				tomod.midiData[0] = MIDI_NOTEOFF | noteOnChannel[data1][channel];
                tomod.midiData[1] = transposed[data1][channel];
            }
            transposed[data1][channel] = data1;
			noteOnChannel[data1][channel] = channel;
        }
		else if (status==MIDI_POLYKEYPRESSURE) {
			int n = data1%12;
			int newdata1 = root + data1 + notetable[n];
			if (newdata1>127 || newdata1<0)
			{
				if (wrap) {
					newdata1 = midiNoteWrap(newdata1);
					tomod.midiData[0] = MIDI_NOTEON | tchannel;
					tomod.midiData[1] = newdata1;
				}
				else {
					discard = true;
				}
			}
			else
			{
				tomod.midiData[0] = MIDI_NOTEON | tchannel;
				tomod.midiData[1] = (char)newdata1;
			}
		}
        if (!discard) outputs[0].push_back(tomod);
    }
}
Exemplo n.º 3
0
void MidiForceToKey::processMidiEvents(VstMidiEventVec *inputs, VstMidiEventVec *outputs, VstInt32 sampleFrames)
{
	const int tchannel = FLOAT_TO_CHANNEL(fChannel);
	const int nchannel = FLOAT_TO_CHANNEL(fNChannel);
	int transposey    = roundToInt(fTranspose*100.f)-50;
	bool noteswitch[12] = {n0>=0.5f,n1>=0.5f,n2>=0.5f,n3>=0.5f,n4>=0.5f,n5>=0.5f,
		n6>=0.5f,n7>=0.5f,n8>=0.5f,n9>=0.5f,n10>=0.5f,n11>=0.5f};

	for (unsigned int i=0;i<inputs[0].size();i++) {
		VstMidiEvent tomod = inputs[0][i];
		const int status     = tomod.midiData[0] & 0xf0;   // scraping  channel
		const int channel    = tomod.midiData[0] & 0x0f;  // isolating channel (0-15)
		const int data1      = tomod.midiData[1] & 0x7f;
		//int data2	   = tomod.midiData[2] & 0x7f;
		bool discard = false;

		if (status==MIDI_PROGRAMCHANGE)
		{
			if (data1<kNumPrograms && fUsePC>=0.5f) {
				setProgram(data1);
				updateDisplay();
			}
		}
		//set key notes based on "note channel"
		if (channel == nchannel) {
			discard = true;
			if (isNoteOn(tomod)) {
				int n = data1%12;
				if (fNChMode<0.5f && !noteswitch[n])
				{
					noteswitch[n] = true;
					setParameterAutomated(k0+n, 1.f);
				}
				else
				{
					noteswitch[n] = !noteswitch[n];
					setParameterAutomated(k0+n, noteswitch[n] ? 1.f : 0.f);
				}
			}
			else if (isNoteOff(tomod) && fNChMode<0.5f) {
				int n = data1%12;
				noteswitch[n] = false;
				setParameterAutomated(k0+n, 0.f);
			}
		}
		else {
			if (isNoteOn(tomod)) {
				if (!noteswitch[data1%12]) {
					dbg("wrong note " << data1);
					int transpose = 0;
					int j = -1;
					switch (mode)
					{
						//nearest note, down when tied (same as ndc)
					case nearest:
						discard = true;
						while (j<12) {
							if (noteswitch[(data1+j)%12]) {
								transpose = j;
								discard = false;
								break;
							}
							if (j<0) j = -j;
							else j = -j - 1;
						}
						break;
						//always up
					case alwaysup:
						j = 1;
						discard = true;
						while (j<12) {
							if (noteswitch[(data1+j)%12]) {
								transpose = j;
								discard = false;
								break;
							}
							j++;
						}
						break;
						//always down
					case alwaysdown:
						discard = true;
						while (j<12) {
							if (noteswitch[(data1+j)%12]) {
								transpose = j;
								discard = false;
								break;
							}
							j--;
						}
						break;
						//block wrong notes
					case block:
						dbg("block note");
						discard = true;
						transposed[data1][channel]=-999;
						break;
					case off:
					default:
						break;
					}
					tomod.midiData[1] = data1 + transpose;
				}
				//transpose based on notes on "transpose channel"
				if (channel==tchannel)
				{
					dbg("tchannel");
					discard=true;
					int root=FLOAT_TO_MIDI(fRoot);
					int m = 0;
					int counter=0;
					if (tomod.midiData[1] > root) {
						while (counter<(tomod.midiData[1]-root)) {
							m++;
							if (noteswitch[(root+m)%12]) counter++;
							if (tomod.midiData[1] - m == root) break;
						}
					}
					else if (tomod.midiData[1] < root) {
						while (counter>(tomod.midiData[1]-root)) {
							m++;
							if (noteswitch[(root-m)%12]) counter--;
							if (tomod.midiData[1] + m == root) break;
						}
					}
					transposey = counter;
					setParameterAutomated(kTranspose, ((float)(transposey+50))*0.01f);
				}
			}
		}
		if (!discard) {
			dbg("keep event");
			if (isNoteOn(tomod) || status==MIDI_POLYKEYPRESSURE) {
				if (transposey > 0) {
					//move the note up to the right scale degree
					int counter=0;
					int m=0;
					while (counter<transposey) {
						m++;
						if (noteswitch[(tomod.midiData[1]+m)%12]) counter++;
						if ((tomod.midiData[1]+m) == 127) break;
					}
					tomod.midiData[1] += m;
				}
				else if (transposey < 0) {
					//move the note down the scale
					int counter=0;
					int m=0;
					while (counter>transposey) {
						m++;
						if (noteswitch[(tomod.midiData[1]-m)%12]) counter--;
						if ((tomod.midiData[1]-m) == 0) break;
					}
					tomod.midiData[1] -= m;
				}
				if (isNoteOn(tomod)) 
					transposed[data1][channel] = tomod.midiData[1];
			}
			else if (isNoteOff(tomod)) {
				dbg("noteoff " << data1 << " transposed " << transposed[data1][channel]);
				if (channel == tchannel) discard = true;
				// always transpose noteoff by the same amount as the noteon was transposed
				if (transposed[data1][channel]==-999) discard = true;
				else tomod.midiData[1] = transposed[data1][channel];
				transposed[data1][channel] = data1;
			}
			if (!discard) outputs[0].push_back(tomod);
		}
	}
}