Ejemplo n.º 1
0
void PianoRoll::mouseDoubleClick (const MouseEvent& e)
{
	if (e.mods.isLeftButtonDown())
	{
		bool snap = snapToGrid != e.mods.isShiftDown();
		int n = (int)((float)(getHeight()-e.y)*128.f/(float)getHeight());
		double t = pixelsToPpq((float)e.x,true);
		double accurateTime = pixelsToPpq((float)e.x,false);
		hoveringNoteIndex = sequence->getIndexOfNote(n,accurateTime);
		draggingNoteTimeDelta = 0.0;
		draggingNoteTransposition = 0;
		draggingNoteNumber = n;
		draggingNoteVelocity = originalNoteVelocity = 127;
		draggingNoteLength = stepLengthInPpq-1;
		draggingNoteStartTime = snap ? t : accurateTime;
		draggingNoteChannel = defaultChannel;
		lastDragTime = snap ? t : accurateTime;
		if (hoveringNoteIndex == No_Note) {
			if (sequence->getNumEvents()==0 && timeline->getLength()==0)
				timeline->setLoop(0,quarterNotesPerBar*ceil((lastDragTime+1)/(timebase*quarterNotesPerBar)));
			sequence->addNote(MidiMessage(MIDI_NOTEON | draggingNoteChannel, draggingNoteNumber, draggingNoteVelocity, draggingNoteStartTime),
							  MidiMessage(MIDI_NOTEOFF | draggingNoteChannel, draggingNoteNumber, 0, draggingNoteStartTime+draggingNoteLength));
			//sequence->updateMatchedPairs();
			addToSelection(sequence->getEventPointer(sequence->getIndexOfNote(n,draggingNoteStartTime,true)));
			sendChangeMessage();
			noteLayer->repaint();
		}
	}
}
Ejemplo n.º 2
0
void PianoRoll::mouseDown (const MouseEvent& e)
{
	bool snap = snapToGrid != e.mods.isShiftDown();
	int n = (int)((float)(getHeight()-e.y)*128.f/(float)getHeight());
	double t = pixelsToPpq((float)e.x,true);
	double accurateTime = pixelsToPpq((float)e.x,false);
	hoveringNoteIndex = sequence->getIndexOfNote(n,accurateTime);
	if (hoveringNoteIndex != No_Note) {
		hoveringNote = sequence->getEventPointer(hoveringNoteIndex);
		//existing note
		draggingNoteTimeDelta = 0.0;
		draggingNoteTransposition = 0;
		draggingNoteNumber = n;
		draggingNoteVelocity = originalNoteVelocity = hoveringNote->message.getVelocity();
		draggingNoteLength = sequence->getTimeOfMatchingKeyUp(hoveringNoteIndex) - sequence->getEventTime(hoveringNoteIndex);
		draggingNoteStartTime = sequence->getEventTime(hoveringNoteIndex);
		draggingNoteChannel = hoveringNote->message.getChannel()-1;
		draggingNoteEndOffset = (draggingNoteStartTime + draggingNoteLength) - accurateTime;
		lastDragTime = snap ? t : accurateTime;
		if (!selectedNotes.contains(hoveringNote)) {
			clearSelection();
			addToSelection(hoveringNote);
			jassert(hoveringNote->noteOffObject!=0);
			DBG("n=" + String(n) + "v=" + String(draggingNoteVelocity));
		}
		hoveringNoteIndex -= Dragging_A_Note;
	}
	else if (e.mods.isAltDown()){
		//make a new note
		wasResizing=true;
		clearSelection();
		hoveringNoteIndex = New_Note;
		draggingNoteNumber = n;
		draggingNoteVelocity = originalNoteVelocity = 127;
		draggingNoteLength = stepLengthInPpq-1;
		draggingNoteStartTime = snap ? t : accurateTime;
		draggingNoteChannel = defaultChannel;
		draggingNoteTimeDelta = 0.0;
		draggingNoteTransposition = 0;
		lastDragTime = snap ? t : accurateTime;
		if (sequence->getNumEvents()==0 && timeline->getLength()==0)
			timeline->setLoop(0,quarterNotesPerBar*ceil((lastDragTime+1)/(timebase*quarterNotesPerBar)));
		plugin->getCallbackLock().enter();
		sequence->addNote(MidiMessage(MIDI_NOTEON | draggingNoteChannel, draggingNoteNumber, draggingNoteVelocity, draggingNoteStartTime),
						  MidiMessage(MIDI_NOTEOFF | draggingNoteChannel, draggingNoteNumber, 0, draggingNoteStartTime+draggingNoteLength));
		plugin->getCallbackLock().exit();
		sequence->updateMatchedPairs();
		hoveringNote = sequence->getEventPointer(sequence->getIndexOfNote(draggingNoteNumber,draggingNoteStartTime,true));
		addToSelection(hoveringNote);
		sendChangeMessage();
	}
	else 
		clearSelection();
	noteLayer->repaint();
}
Ejemplo n.º 3
0
MidiMessage MidiMessage::channelPressureChange (const int channel, const int pressure) noexcept
{
    jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
    jassert (isPositiveAndBelow (pressure, 128));

    return MidiMessage (MidiHelpers::initialByte (0xd0, channel), pressure & 0x7f);
}
Ejemplo n.º 4
0
MidiMessage MidiMessage::noteOff (const int channel, const int noteNumber) noexcept
{
    jassert (channel > 0 && channel <= 16);
    jassert (isPositiveAndBelow (noteNumber, 128));

    return MidiMessage (MidiHelpers::initialByte (0x80, channel), noteNumber & 127, 0);
}
Ejemplo n.º 5
0
void DexedAudioProcessor::setDxValue(int offset, int v) {
    if (offset < 0)
        return;

    if ( data[offset] != v ) {
        TRACE("setting dx %d %d", offset, v);
        data[offset] = v;
    } else {
        TRACE("ignoring dx7 same values %d %d", offset, v);
        return;
    }

    refreshVoice = true;

    // MIDDLE C (transpose)
    if (offset == 144)
        panic();
    
    if (!sendSysexChange)
        return;
    
    uint8 msg[7] = { 0xF0, 0x43, 0x10, offset > 127, 0, (uint8) v, 0xF7 };
    msg[2] = 0x10 | sysexComm.getChl();
    msg[4] = offset & 0x7F;
    
    if ( sysexComm.isOutputActive() ) {
        sysexComm.send(MidiMessage(msg,7));
    }
}
Ejemplo n.º 6
0
const MidiMessage createFromHexData (const String &hexData)
{
	MemoryBlock bl;
	bl.loadFromHexString(hexData);

	return (MidiMessage ((uint8*)bl.getData(), (int)bl.getSize()));
}
Ejemplo n.º 7
0
MidiMessage MidiMessage::controllerEvent (const int channel, const int controllerType, const int value) noexcept
{
    // the channel must be between 1 and 16 inclusive
    jassert (channel > 0 && channel <= 16);

    return MidiMessage (MidiHelpers::initialByte (0xb0, channel),
                        controllerType & 127, value & 127);
}
Ejemplo n.º 8
0
MidiMessage MidiMessage::noteOn (const int channel, const int noteNumber, const uint8 velocity) noexcept
{
    jassert (channel > 0 && channel <= 16);
    jassert (isPositiveAndBelow (noteNumber, 128));

    return MidiMessage (MidiHelpers::initialByte (0x90, channel),
                        noteNumber & 127, MidiHelpers::validVelocity (velocity));
}
Ejemplo n.º 9
0
bool Gsp1101::sendCabData(UserCab const& userCab, unsigned char permFlag)
{
    std::auto_ptr<MidiBuffer> midiBuffer = userCab.createOutMidiBuffer(permFlag == 0x02);

    // F0 00 00 10 00 5F 01 (procedure 73) 00 30 01 (cab index) (permanence flag) (checksum) F7
    unsigned char cabEnd[]= { 0xf0, 0x00, 0x00, 0x10, 0x00, 0x5f, 0x01, 0x73, 0x00, 0x30, 0x01, 0x00, 0x00, 0x00, 0xf7 };

    cabEnd[sizeof(cabEnd) - 4] = static_cast<unsigned char>(userCab.getSlot() - 1);
    cabEnd[sizeof(cabEnd) - 3] = permFlag;
    unsigned char checksum = 0x00;
    for (size_t i = 0; i < sizeof(cabEnd) - 3; ++i)
    {
        checksum ^= cabEnd[i + 1];
    }
    cabEnd[sizeof(cabEnd) - 2] = checksum;
    MidiMessage midiMessage (cabEnd, sizeof(cabEnd));
    midiBuffer->addEvent (midiMessage, midiBuffer->getNumEvents() + 1);

    if (openMidi())
    {
        //Logger::outputDebugString("midiBuffer size = " + String(midiBuffer->getNumEvents()));
        MidiBuffer::Iterator i (*midiBuffer);
        const uint8* data;
        int len, time, count = midiBuffer->getNumEvents();
        bool rcvOK = false;
        while (i.getNextEvent (data, len, time) && deviceReady_M)
        {
            lastMidiInput_M.setSize(0);
            midiOutput_M->sendMessageNow(MidiMessage(data, len));

            unsigned char const testOK[]       = { 0x00, 0x00, 0x10, 0x00, 0x5f, 0x01, 0x7e, 0x00, 0x7a, 0x4a, };
            unsigned char const testOKcabEnd[] = { 0x00, 0x00, 0x10, 0x00, 0x5f, 0x01, 0x7e, 0x00, 0x73, 0x43, };

            if (--count > 0)
            {
                Logger::outputDebugString("\nMidiMessage to send:" + asHex(data, 16, true) + " ...");
                rcvOK = waitForMidiInput(testOK);
            }
            else
            {
                Logger::outputDebugString("\nMidiMessage to send:" + asHex(data, sizeof(cabEnd), true));
                rcvOK = waitForMidiInput(testOKcabEnd);
            }
            if (!rcvOK)
            {
                break;
            }
        }
        deviceReady_M = true;
        return rcvOK;
    }
    else
    {
        AlertWindow::showMessageBox (AlertWindow::WarningIcon, "Warning", "MIDI Device Not Found");
        return false;
    }
}
Ejemplo n.º 10
0
MidiMessage MidiMessage::createSysExMessage (const void* sysexData, const int dataSize)
{
    HeapBlock<uint8> m ((size_t) dataSize + 2);

    m[0] = 0xf0;
    memcpy (m + 1, sysexData, (size_t) dataSize);
    m[dataSize + 1] = 0xf7;

    return MidiMessage (m, dataSize + 2);
}
Ejemplo n.º 11
0
MidiMappingGui::MidiMappingGui()
{
	m_receiver = NULL;
	m_receiverMember = NULL;
	m_minSubIdLevel = 0;
	m_maxSubIdLevel = 4;

	// System Messages
	m_controlMessages.insert(MidiMessage(MIDI_STATUS_CC, MIDI_CC_ALL_NOTES_OFF, 0), "ctrlAllNotesOff");


	/*
	 * --> Here is the Identity Request message:
		0xF0  SysEx
		0x7E  Non-Realtime
		0x7F  The SysEx channel. Could be from 0x00 to 0x7F. Here we set it to "disregard channel".
		0x06  Sub-ID -- General Information
		0x01  Sub-ID2 -- Identity Request
		0xF7  End of SysEx

		Here is the Identity Reply message:

		0xF0  SysEx
		0x7E  Non-Realtime
		0x7F  The SysEx channel. Could be from 0x00 to 0x7F. Here we set it to "disregard channel".
		0x06  Sub-ID -- General Information
		0x02  Sub-ID2 -- Identity Reply
		0xID  Manufacturer's ID				--> "Educational Use  0x7D"
		0xf1  The f1 and f2 bytes make up the family code. Each
		0xf2  manufacturer assigns different family codes to his products.
		0xp1  The p1 and p2 bytes make up the model number. Each
		0xp2  manufacturer assigns different model numbers to his products.
		0xv1  The v1, v2, v3 and v4 bytes make up the version number.
		0xv2
		0xv3
		0xv4
		0xF7  End of SysEx
	 *
	 */
	QByteArray identReqSysexMsg;
	identReqSysexMsg   << 0x7e << 0x7f << 0x06 << 0x01;
	QByteArray identReqSysexReply;
	identReqSysexReply << 0x7e << 0x7f << 0x06 << 0x02
			<< 0x7d
			<< 0x00 << 0x01						//
			<< 0x09 << 0x00						// N900 model
			<< MIDIJ_MAJORVERSION_HI << MIDIJ_MAJORVERSION_LO
			<< MIDIJ_MINORVERSION_HI << MIDIJ_MINORVERSION_LO;	// version 0.1-1 (same has build)

	// SysexAction for Identity Reply....
	MidiSysexAction* sysexAction = new MidiSysexActionEx(identReqSysexMsg, identReqSysexReply, this);
	m_midiSysexActionMap.insert(sysexAction->getMapKey(), sysexAction);
	m_midiSysexBg = NULL;
}
Ejemplo n.º 12
0
bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result, int& samplePosition) noexcept
{
    if (data >= buffer.data.end())
        return false;

    samplePosition = MidiBufferHelpers::getEventTime (data);
    const int itemSize = MidiBufferHelpers::getEventDataSize (data);
    result = MidiMessage (data + sizeof (int32) + sizeof (uint16), itemSize, samplePosition);
    data += sizeof (int32) + sizeof (uint16) + (size_t) itemSize;

    return true;
}
Ejemplo n.º 13
0
MidiMessage MidiMessage::aftertouchChange (const int channel,
                                           const int noteNum,
                                           const int aftertouchValue) noexcept
{
    jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
    jassert (isPositiveAndBelow (noteNum, 128));
    jassert (isPositiveAndBelow (aftertouchValue, 128));

    return MidiMessage (MidiHelpers::initialByte (0xa0, channel),
                        noteNum & 0x7f,
                        aftertouchValue & 0x7f);
}
Ejemplo n.º 14
0
void CtrlrMidiDevice::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
{
	_MIN(getProperty(Ids::name), message);

#ifdef JUCE_LINUX
    uint8 *ptr = message.getRawData();

    if (!message.isSysEx() && *(ptr + (message.getRawDataSize() - 1)) == 0xf7)
    {
        dataCollector.append (ptr, message.getRawDataSize());

        deviceListeners.call (&CtrlrMidiDevice::Listener::handleMIDIFromDevice, MidiMessage (dataCollector.getData(), dataCollector.getSize()));

        return;
    }
#endif

	if (message.isSysEx())
	{
#ifdef JUCE_LINUX


        if (*(ptr + (message.getRawDataSize() - 1)) == 0xf7)
        {
            deviceListeners.call (&CtrlrMidiDevice::Listener::handleMIDIFromDevice, message);
        }
        else
        {
            dataCollector = MemoryBlock (ptr, message.getRawDataSize());
        }
#else
		deviceListeners.call (&CtrlrMidiDevice::Listener::handleMIDIFromDevice, message);
#endif
	}
	else
	{
        lastMessageWasSysex = false;

		for (int i=0; i<deviceListeners.size(); i++)
		{
			const int ch = deviceListeners.getListeners() [i]->getListenerInputMidiChannel();

			if (ch == message.getChannel() || ch == 0 || message.getChannel() == 0)
			{
				deviceListeners.getListeners() [i]->handleMIDIFromDevice (message);
			}
		}
	}
}
Ejemplo n.º 15
0
//==============================================================================
void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber, const double time, Array<MidiMessage>& dest)
{
    bool doneProg = false;
    bool donePitchWheel = false;
    bool doneControllers[128] = { 0 };

    for (int i = list.size(); --i >= 0;)
    {
        const MidiMessage& mm = list.getUnchecked(i)->message;

        if (mm.isForChannel (channelNumber) && mm.getTimeStamp() <= time)
        {
            if (mm.isProgramChange() && ! doneProg)
            {
                doneProg = true;
                dest.add (MidiMessage (mm, 0.0));
            }
            else if (mm.isPitchWheel() && ! donePitchWheel)
            {
                donePitchWheel = true;
                dest.add (MidiMessage (mm, 0.0));
            }
            else if (mm.isController())
            {
                const int controllerNumber = mm.getControllerNumber();
                jassert (isPositiveAndBelow (controllerNumber, 128));

                if (! doneControllers[controllerNumber])
                {
                    doneControllers[controllerNumber] = true;
                    dest.add (MidiMessage (mm, 0.0));
                }
            }
        }
    }
}
Ejemplo n.º 16
0
const CtrlrMidiMessageEx CtrlrSysexProcessor::sysexMessageFromString (const String &formula, const int value, const int channel)
{
	MidiMessage m;
	MemoryBlock bl(0,true);
	StringArray tokens;
	tokens.addTokens (formula, " ;:", "\"");

	for (int i=0; i<tokens.size(); i++)
	{
		const int d = jmin<int> (tokens[i].getHexValue32(),255);
		bl.append (&d, 1);
	}

	Array <CtrlrSysexToken> tokenArray = sysExToTokenArray(formula);

	CtrlrMidiMessageEx mex;
	mex.m  = MidiMessage (bl.getData(), bl.getSize());
	mex.setTokenArray(tokenArray);
	return (mex);
}
Ejemplo n.º 17
0
void stepQuickEdit::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
{
    //[UsercomboBoxChanged_Pre]
    //[/UsercomboBoxChanged_Pre]

    if (comboBoxThatHasChanged == typeCombo)
    {
        //[UserComboBoxCode_typeCombo] -- add your combo box handling code here..
		if (midiMessage == 0)
			return;

		switch (typeCombo->getSelectedId())
		{
			case noteOn:
				if (!midiMessage->isMulti())
				{
					if (!midiMessage->getMidiMessage())
						return;

					if (midiMessage->getMidiMessage()->isNoteOn())
					{
						midiMessage->setMidiMessage (*midiMessage->getMidiMessage());
					}
					else
					{
						midiMessage->setMidiMessage (MidiMessage::noteOn (1, 64, 1.0f));
					}
				}
				else
				{
					midiMessage->setMidiMessage (MidiMessage::noteOn (1, 64, 1.0f));
				}
				break;

			case Controller:
				if (!midiMessage->isMulti())
				{
					if (!midiMessage->getMidiMessage())
						return;

					if (midiMessage->getMidiMessage()->isController())
					{
						midiMessage->setMidiMessage (*midiMessage->getMidiMessage());
					}
					else
					{
						midiMessage->setMidiMessage (MidiMessage::controllerEvent (1, 1, 1));
					}
				}
				else
				{
					if (midiMessage->getMidiMessage()->isController())
					{
						if (!midiMessage->getMidiMessage())
							return;

						midiMessage->setMidiMessage (*midiMessage->getMidiMessage());
					}
					else
					{
						midiMessage->setMidiMessage (MidiMessage::controllerEvent (1, 1, 1));
					}
				}
				break;

			case ProgramChange:
				if (!midiMessage->getMidiMessage())
						return;

				if (midiMessage->getMidiMessage()->isProgramChange())
				{
					if (!midiMessage->getMidiMessage())
						return;

					midiMessage->setMidiMessage (*midiMessage->getMidiMessage());
				}
				else
				{
					midiMessage->setMidiMessage (MidiMessage::programChange (1, 1));
				}
				break;

			case SysEx:
				if (!midiMessage->getMidiMessage())
						return;

				if (midiMessage->getMidiMessage()->isSysEx())
				{
					if (!midiMessage->getMidiMessage())
						return;

					midiMessage->setMidiMessage (*midiMessage->getMidiMessage());
				}
				else
				{
					uint8 d[4];
					d[0] = 0xf0;
					d[1] = 0x00;
					d[2] = 0x0f;

					midiMessage->setMidiMessage (MidiMessage (d, 3, 0));
				}
				break;

			default:
				break;
		}

		messageTypeChanged();
        //[/UserComboBoxCode_typeCombo]
    }

    //[UsercomboBoxChanged_Post]
    //[/UsercomboBoxChanged_Post]
}
Ejemplo n.º 18
0
void test3()
{
    int bufferSize = 1000;
    char *buffer = AllocateAligned4( bufferSize );

// single message tests
    // empty message
    {
        std::memset( buffer, 0x74, bufferSize );
        OutboundPacketStream ps( buffer, bufferSize );
        ps << BeginMessage( "/no_arguments" )
            << EndMessage;
        assertEqual( ps.IsReady(), true );
        ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) );
        std::cout << m << "\n";\
    }

    TEST_PACK_UNPACK( "/a_bool", true, bool, AsBool );
    TEST_PACK_UNPACK( "/a_bool", false, bool, AsBool );
    TEST_PACK_UNPACK( "/a_bool", (bool)1, bool, AsBool );


#ifndef _OBJC_OBJC_H_
    TEST_PACK_UNPACK0( "/nil", Nil, true, IsNil );
#endif
    TEST_PACK_UNPACK0( "/nil", OscNil, true, IsNil );
    TEST_PACK_UNPACK0( "/inf", Infinitum, true, IsInfinitum );

    TEST_PACK_UNPACK( "/an_int", (int32)1234, int32, AsInt32 );

    TEST_PACK_UNPACK( "/a_float", 3.1415926f, float, AsFloat );

    TEST_PACK_UNPACK( "/a_char", 'c', char, AsChar );

    TEST_PACK_UNPACK( "/an_rgba_color", RgbaColor(0x22334455), uint32, AsRgbaColor );

    TEST_PACK_UNPACK( "/a_midi_message", MidiMessage(0x7F), uint32, AsMidiMessage );

    TEST_PACK_UNPACK( "/an_int64", (int64)(0xFFFFFFFF), int64, AsInt64 );

    TEST_PACK_UNPACK( "/a_time_tag", TimeTag(0xFFFFFFFF), uint64, AsTimeTag );

    TEST_PACK_UNPACK( "/a_double", (double)3.1415926, double, AsDouble );

    // blob
    {
        char blobData[] = "abcd";
        std::memset( buffer, 0x74, bufferSize );
        OutboundPacketStream ps( buffer, bufferSize );
        ps << BeginMessage( "/a_blob" )
            << Blob( blobData, 4 )
            << EndMessage;
        assertEqual( ps.IsReady(), true );
        ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) );
        std::cout << m << "\n";

        const void *value;
        osc_bundle_element_size_t size;
        m.ArgumentsBegin()->AsBlob( value, size );
        assertEqual( size, (osc_bundle_element_size_t)4 );
        assertEqual( (memcmp( value, blobData, 4 ) == 0), true );
    }

    // array
    {
        int32 arrayData[] = {1,2,3,4};
        const std::size_t sourceArrayItemCount = 4;
        std::memset( buffer, 0x74, bufferSize );
        OutboundPacketStream ps( buffer, bufferSize );
        ps << BeginMessage( "/an_array" )
            << BeginArray;
        for( std::size_t j=0; j < sourceArrayItemCount; ++j )
            ps << arrayData[j];
        ps << EndArray << EndMessage;
        assertEqual( ps.IsReady(), true );
        ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) );
        std::cout << m << "\n";

        ReceivedMessageArgumentIterator i = m.ArgumentsBegin();
        assertEqual( i->IsArrayBegin(), true );
        assertEqual( i->ComputeArrayItemCount(), sourceArrayItemCount );
        std::size_t arrayItemCount = i->ComputeArrayItemCount();
        ++i; // move past array begin marker        
        for( std::size_t j=0; j < arrayItemCount; ++j ){
            assertEqual( true, i->IsInt32() );
            int32 k = i->AsInt32();
            assertEqual( k, arrayData[j] );
            ++i;
        }

        assertEqual( i->IsArrayEnd(), true );
    }



    TEST_PACK_UNPACK( "/a_string", "hello world", const char*, AsString );

    TEST_PACK_UNPACK( "/a_symbol", Symbol("foobar"), const char*, AsSymbol );


    // nested bundles, and multiple messages in bundles...

    {
        std::memset( buffer, 0x74, bufferSize );
        OutboundPacketStream ps( buffer, bufferSize );
        ps << BeginBundle()
            << BeginMessage( "/message_one" ) << 1 << 2 << 3 << 4 << EndMessage
            << BeginMessage( "/message_two" ) << 1 << 2 << 3 << 4 << EndMessage
            << BeginMessage( "/message_three" ) << 1 << 2 << 3 << 4 << EndMessage
            << BeginMessage( "/message_four" ) << 1 << 2 << 3 << 4 << EndMessage
            << EndBundle;
        assertEqual( ps.IsReady(), true );
        ReceivedBundle b( ReceivedPacket(ps.Data(), ps.Size()) );
        std::cout << b << "\n";
    }
}
GraphicsMidiInputItem::GraphicsMidiInputItem(QDomElement controlNode, const PixmapMap& pixmapMap)
{
	// map a midi message to a
	m_inputMidiMessages.append(MidiMessage(controlNode));

	m_name = controlNode.attribute(CONTROL_NAME, "");
	m_groupName = controlNode.attribute(CONTROL_GROUP, "");
	QString debugColor = controlNode.attribute("debug");

	GraphicsMidiArea area = parseAreaElement(controlNode);
	if (area.isNull())
		return;

	QString mask = parsePixmapMask(controlNode);

	setSceneRect(area.rect);
	bool hasRanged = false;

	// get states
	QDomElement stateNode = controlNode.firstChildElement("state");
	int rangeMarker;
	QPixmap backgroundPixmap = pixmapFromMap(GuiUtils::background, m_sceneRect, pixmapMap, mask);
	ushort minRangeId, maxRangeId;
	while (!stateNode.isNull())
	{
		QString state = stateNode.text();
		QString stateValue = stateNode.attribute("value").trimmed();

		// map range to m_state2Pixmap
		rangeMarker = stateValue.indexOf(INPUT_STATE_RANGEMARKER);
		if (rangeMarker > 0)
		{
			hasRanged = true;
			bool ok = false;
			//qDebug() << state << stateValue  << rangeMarker << stateValue.left(rangeMarker) << stateValue.mid(rangeMarker + 1);
			minRangeId = stateValue.left(rangeMarker).toUShort(&ok, 0);
			if (ok)
				maxRangeId = stateValue.mid(rangeMarker + 1).toUShort(&ok, 0);
			if (!ok)
			{
				qCritical() << "error parsing:" << stateValue << "; line:" << stateNode.lineNumber();
				return;
			}

			QPixmap pixmap = pixmapFromState(stateNode, backgroundPixmap, m_sceneRect, pixmapMap, mask);
			if (!pixmap.isNull())
			{
				checkDebug(debugColor, pixmap, area);
				// map range to m_state2Pixmap
				m_state2Pixmap.insert(maxRangeId, pixmap);
				m_range2State.insert(minRangeId, maxRangeId); // add ranged value
			}
		}
		else
		{
			bool ok = false;
			ushort stateId = stateValue.toUShort(&ok, 0);
			if (pixmapMap.contains(state) && ok)
			{
//				QPixmap pixmap = pixmapMap.value(state).copy(rect);
				QPixmap pixmap = pixmapFromState(stateNode, backgroundPixmap, m_sceneRect, pixmapMap, mask);
				checkDebug(debugColor, pixmap, area);

				m_state2Pixmap.insert(stateId, pixmap);
				m_range2State.insert(stateId, stateId); // support for ranged values
				if (GuiUtils::isBackground(state))
				{
					m_offState = stateId;
					setPixmap(pixmap);
				}
			}
		}
		stateNode = stateNode.nextSiblingElement("state");
	}

	if (!hasRanged)
		m_range2State.clear(); // no ranged values after all...

/*	QPixmap pixmap = pixmapMap[GuiUtils::background];

if (0) {
	setPixmap(pixmap.copy(rect));
} else {
QPixmap tmp = pixmap.copy(rect);
QPainter dc(&tmp);
dc.setPen(Qt::green);
dc.drawRect(0,0,rect.width()-1, rect.height()-1);
setPixmap(tmp);
}
*/
	setPos(m_sceneRect.topLeft());
	setZValue(2);

	m_hasInput = true;
}
Ejemplo n.º 20
0
void InstanceProcessor::receiveMidiByte(int port, int value)
{
    m_midi.addEvent(MidiMessage(port, value), 0);
}
Ejemplo n.º 21
0
    void runTest() override
    {
        beginTest ("initialisation");
        {
            MPEZoneLayout layout;
            expectEquals (layout.getNumZones(), 0);
        }

        beginTest ("adding zones");
        {
            MPEZoneLayout layout;

            expect (layout.addZone (MPEZone (1, 7)));

            expectEquals (layout.getNumZones(), 1);
            expectEquals (layout.getZoneByIndex (0)->getMasterChannel(), 1);
            expectEquals (layout.getZoneByIndex (0)->getNumNoteChannels(), 7);

            expect (layout.addZone (MPEZone (9, 7)));

            expectEquals (layout.getNumZones(), 2);
            expectEquals (layout.getZoneByIndex (0)->getMasterChannel(), 1);
            expectEquals (layout.getZoneByIndex (0)->getNumNoteChannels(), 7);
            expectEquals (layout.getZoneByIndex (1)->getMasterChannel(), 9);
            expectEquals (layout.getZoneByIndex (1)->getNumNoteChannels(), 7);

            expect (! layout.addZone (MPEZone (5, 3)));

            expectEquals (layout.getNumZones(), 3);
            expectEquals (layout.getZoneByIndex (0)->getMasterChannel(), 1);
            expectEquals (layout.getZoneByIndex (0)->getNumNoteChannels(), 3);
            expectEquals (layout.getZoneByIndex (1)->getMasterChannel(), 9);
            expectEquals (layout.getZoneByIndex (1)->getNumNoteChannels(), 7);
            expectEquals (layout.getZoneByIndex (2)->getMasterChannel(), 5);
            expectEquals (layout.getZoneByIndex (2)->getNumNoteChannels(), 3);

            expect (! layout.addZone (MPEZone (5, 4)));

            expectEquals (layout.getNumZones(), 2);
            expectEquals (layout.getZoneByIndex (0)->getMasterChannel(), 1);
            expectEquals (layout.getZoneByIndex (0)->getNumNoteChannels(), 3);
            expectEquals (layout.getZoneByIndex (1)->getMasterChannel(), 5);
            expectEquals (layout.getZoneByIndex (1)->getNumNoteChannels(), 4);

            expect (! layout.addZone (MPEZone (6, 4)));

            expectEquals (layout.getNumZones(), 2);
            expectEquals (layout.getZoneByIndex (0)->getMasterChannel(), 1);
            expectEquals (layout.getZoneByIndex (0)->getNumNoteChannels(), 3);
            expectEquals (layout.getZoneByIndex (1)->getMasterChannel(), 6);
            expectEquals (layout.getZoneByIndex (1)->getNumNoteChannels(), 4);
        }

        beginTest ("querying zones");
        {
            MPEZoneLayout layout;

            layout.addZone (MPEZone (2, 5));
            layout.addZone (MPEZone (9, 4));

            expect (layout.getZoneByMasterChannel (1)  == nullptr);
            expect (layout.getZoneByMasterChannel (2)  != nullptr);
            expect (layout.getZoneByMasterChannel (3)  == nullptr);
            expect (layout.getZoneByMasterChannel (8)  == nullptr);
            expect (layout.getZoneByMasterChannel (9)  != nullptr);
            expect (layout.getZoneByMasterChannel (10) == nullptr);

            expectEquals (layout.getZoneByMasterChannel (2)->getNumNoteChannels(), 5);
            expectEquals (layout.getZoneByMasterChannel (9)->getNumNoteChannels(), 4);

            expect (layout.getZoneByFirstNoteChannel (2)  == nullptr);
            expect (layout.getZoneByFirstNoteChannel (3)  != nullptr);
            expect (layout.getZoneByFirstNoteChannel (4)  == nullptr);
            expect (layout.getZoneByFirstNoteChannel (9)  == nullptr);
            expect (layout.getZoneByFirstNoteChannel (10) != nullptr);
            expect (layout.getZoneByFirstNoteChannel (11) == nullptr);

            expectEquals (layout.getZoneByFirstNoteChannel (3)->getNumNoteChannels(), 5);
            expectEquals (layout.getZoneByFirstNoteChannel (10)->getNumNoteChannels(), 4);

            expect (layout.getZoneByNoteChannel (2)  == nullptr);
            expect (layout.getZoneByNoteChannel (3)  != nullptr);
            expect (layout.getZoneByNoteChannel (4)  != nullptr);
            expect (layout.getZoneByNoteChannel (6)  != nullptr);
            expect (layout.getZoneByNoteChannel (7)  != nullptr);
            expect (layout.getZoneByNoteChannel (8)  == nullptr);
            expect (layout.getZoneByNoteChannel (9)  == nullptr);
            expect (layout.getZoneByNoteChannel (10) != nullptr);
            expect (layout.getZoneByNoteChannel (11) != nullptr);
            expect (layout.getZoneByNoteChannel (12) != nullptr);
            expect (layout.getZoneByNoteChannel (13) != nullptr);
            expect (layout.getZoneByNoteChannel (14) == nullptr);

            expectEquals (layout.getZoneByNoteChannel (5)->getNumNoteChannels(), 5);
            expectEquals (layout.getZoneByNoteChannel (13)->getNumNoteChannels(), 4);
        }

        beginTest ("clear all zones");
        {
            MPEZoneLayout layout;

            expect (layout.addZone (MPEZone (1, 7)));
            expect (layout.addZone (MPEZone (10, 2)));
            layout.clearAllZones();

            expectEquals (layout.getNumZones(), 0);
        }

        beginTest ("process MIDI buffers");
        {
            MPEZoneLayout layout;
            MidiBuffer buffer;

            buffer = MPEMessages::addZone (MPEZone (1, 7));
            layout.processNextMidiBuffer (buffer);

            expectEquals (layout.getNumZones(), 1);
            expectEquals (layout.getZoneByIndex (0)->getMasterChannel(), 1);
            expectEquals (layout.getZoneByIndex (0)->getNumNoteChannels(), 7);

            buffer = MPEMessages::addZone (MPEZone (9, 7));
            layout.processNextMidiBuffer (buffer);

            expectEquals (layout.getNumZones(), 2);
            expectEquals (layout.getZoneByIndex (0)->getMasterChannel(), 1);
            expectEquals (layout.getZoneByIndex (0)->getNumNoteChannels(), 7);
            expectEquals (layout.getZoneByIndex (1)->getMasterChannel(), 9);
            expectEquals (layout.getZoneByIndex (1)->getNumNoteChannels(), 7);

            MPEZone zone (1, 10);

            buffer = MPEMessages::addZone (zone);
            layout.processNextMidiBuffer (buffer);

            expectEquals (layout.getNumZones(), 1);
            expectEquals (layout.getZoneByIndex (0)->getMasterChannel(), 1);
            expectEquals (layout.getZoneByIndex (0)->getNumNoteChannels(), 10);

            zone.setPerNotePitchbendRange (33);
            zone.setMasterPitchbendRange (44);

            buffer = MPEMessages::masterPitchbendRange (zone);
            buffer.addEvents (MPEMessages::perNotePitchbendRange (zone), 0, -1, 0);

            layout.processNextMidiBuffer (buffer);

            expectEquals (layout.getZoneByIndex (0)->getPerNotePitchbendRange(), 33);
            expectEquals (layout.getZoneByIndex (0)->getMasterPitchbendRange(), 44);
        }

        beginTest ("process individual MIDI messages");
        {
            MPEZoneLayout layout;

            layout.processNextMidiEvent (MidiMessage (0x80, 0x59, 0xd0));  // unrelated note-off msg
            layout.processNextMidiEvent (MidiMessage (0xb1, 0x64, 0x06));  // RPN part 1
            layout.processNextMidiEvent (MidiMessage (0xb1, 0x65, 0x00));  // RPN part 2
            layout.processNextMidiEvent (MidiMessage (0xb8, 0x0b, 0x66));  // unrelated CC msg
            layout.processNextMidiEvent (MidiMessage (0xb1, 0x06, 0x03));  // RPN part 3
            layout.processNextMidiEvent (MidiMessage (0x90, 0x60, 0x00));  // unrelated note-on msg

            expectEquals (layout.getNumZones(), 1);
            expectEquals (layout.getZoneByIndex (0)->getMasterChannel(), 1);
            expectEquals (layout.getZoneByIndex (0)->getNumNoteChannels(), 3);
        }
    }
Ejemplo n.º 22
0
MidiMessage MidiMessage::programChange (const int channel, const int programNumber) noexcept
{
    jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16

    return MidiMessage (MidiHelpers::initialByte (0xc0, channel), programNumber & 0x7f);
}
Ejemplo n.º 23
0
void RunSendTests( const IpEndpointName& host )
{
    char buffer[IP_MTU_SIZE];
    osc::OutboundPacketStream p( buffer, IP_MTU_SIZE );
	UdpTransmitSocket socket( host );

    p.Clear();
    p << osc::BeginMessage( "/test1" )
            << true << 23 << (float)3.1415 << "hello" << osc::EndMessage;
    socket.Send( p.Data(), p.Size() );

    // test1 message with too few arguments
    p.Clear();
    p << osc::BeginMessage( "/test1" )
            << true << osc::EndMessage;
    socket.Send( p.Data(), p.Size() );

    // test1 message with too many arguments
    p.Clear();
    p << osc::BeginMessage( "/test1" )
            << true << 23 << (float)3.1415 << "hello" << 42 << osc::EndMessage;
    socket.Send( p.Data(), p.Size() );

    // test1 message with wrong argument type
    p.Clear();
    p << osc::BeginMessage( "/test1" )
            << true << 1.0 << (float)3.1415 << "hello" << osc::EndMessage;
    socket.Send( p.Data(), p.Size() );

    p.Clear();
    p << osc::BeginMessage( "/test2" )
            << true << 23 << (float)3.1415 << "hello" << osc::EndMessage;
    socket.Send( p.Data(), p.Size() );

    // send four /test3 messages, each with a different type of argument
    p.Clear();
    p << osc::BeginMessage( "/test3" )
            << true << osc::EndMessage;
    socket.Send( p.Data(), p.Size() );

    p.Clear();
    p << osc::BeginMessage( "/test3" )
            << 23 << osc::EndMessage;
    socket.Send( p.Data(), p.Size() );

    p.Clear();
    p << osc::BeginMessage( "/test3" )
            << (float)3.1415 << osc::EndMessage;
    socket.Send( p.Data(), p.Size() );

    p.Clear();
    p << osc::BeginMessage( "/test3" )
           << "hello" << osc::EndMessage;
    socket.Send( p.Data(), p.Size() );
    

    // send a bundle
    p.Clear();
    p << osc::BeginBundle();

        p << osc::BeginMessage( "/no_arguments" )
            << osc::EndMessage;

        p << osc::BeginMessage( "/a_bool" )
            << true << osc::EndMessage;

        p << osc::BeginMessage( "/a_bool" )
            << false << osc::EndMessage;

        p << osc::BeginMessage( "/a_bool" )
            << (bool)1234 << osc::EndMessage;

        p << osc::BeginMessage( "/nil" )
            << osc::Nil << osc::EndMessage;

        p << osc::BeginMessage( "/inf" )
            << osc::Infinitum << osc::EndMessage;

        p << osc::BeginMessage( "/an_int" ) << 1234 << osc::EndMessage;

        p << osc::BeginMessage( "/a_float" )
            << 3.1415926f << osc::EndMessage;

        p << osc::BeginMessage( "/a_char" )
            << 'c' << osc::EndMessage;

        p << osc::BeginMessage( "/an_rgba_color" )
            << osc::RgbaColor(0x22334455) << osc::EndMessage;

        p << osc::BeginMessage( "/a_midi_message" )
            << MidiMessage(0x7F) << osc::EndMessage;

        p << osc::BeginMessage( "/an_int64" )
            << (int64)(0xFFFFFFF) << osc::EndMessage;

        p << osc::BeginMessage( "/a_time_tag" )
            << osc::TimeTag(0xFFFFFFFUL) << osc::EndMessage;

        p << osc::BeginMessage( "/a_double" )
            << (double)3.1415926 << osc::EndMessage;

        p << osc::BeginMessage( "/a_string" )
            << "hello world" << osc::EndMessage;

        p << osc::BeginMessage( "/a_symbol" )
            << osc::Symbol("foobar") << osc::EndMessage;

        // blob
        {
            char blobData[] = "abcd";

            p << osc::BeginMessage( "/a_blob" )
                << osc::Blob( blobData, 4 )
                << osc::EndMessage;
        }

    p << osc::EndBundle;
    socket.Send( p.Data(), p.Size() );



    // nested bundles, and multiple messages in bundles...
    p.Clear();
    p << osc::BeginBundle( 1234 )
        << osc::BeginMessage( "/an_int" ) << 1 << osc::EndMessage
        << osc::BeginMessage( "/an_int" ) << 2 << osc::EndMessage
        << osc::BeginMessage( "/an_int" ) << 3 << osc::EndMessage
        << osc::BeginMessage( "/an_int" ) << 4 << osc::EndMessage
        << osc::BeginBundle( 12345 )
            << osc::BeginMessage( "/an_int" ) << 5 << osc::EndMessage
            << osc::BeginMessage( "/an_int" ) << 6 << osc::EndMessage
        << osc::EndBundle
    << osc::EndBundle;

    socket.Send( p.Data(), p.Size() );
}
Ejemplo n.º 24
0
void EventNode::process(AudioSampleBuffer &buffer, 
                            MidiBuffer &midiMessages,
                            int& nSamples)
{
	accumulator++;

	if (!isSource) {
		
		if (midiMessages.getNumEvents() > 0) {
			
			std::cout << "Events received by node " << getNodeId() << std::endl;

			 MidiBuffer::Iterator i (midiMessages);
			 MidiMessage message(0xf4);

			 int samplePosition;
			 i.setNextSamplePosition(samplePosition);

			 while (i.getNextEvent (message, samplePosition)) {
				
					//message.getChannel();

					//MidiMessage msgCopy = MidiMessage(message);
					int numbytes = message.getRawDataSize();
					uint8* dataptr = message.getRawData();

					

					std::cout << " Bytes received: " << numbytes << std::endl;
					std::cout << " Message timestamp = " << message.getTimeStamp() << std::endl;

					//std::cout << sizeof(int) << " " << sizeof(uint16) << std::endl;
 
 					std::cout << "   ";
					for (int n = 0; n < numbytes; n++) {
						std::cout << String(*dataptr++) << " ";
					}
					
					std::cout << std::endl << std::endl;
				 	//std::cout << "  Event on channel " << message.getRawData() << std::endl; //<< message.getRawDataSize() << std::endl;

			}


			// accumulator = 0;
		}//MidiBuffer::Iterator = midiMessages.

		//midiMessages.clear();

	} else {

		if (accumulator > 20) {

			uint8 data[95];

			for (int n = 0; n < sizeof(data); n++) {
				data[n] = 1;
			}

			//MidiMessage event = MidiMessage::noteOn(2,1,10.0f);
			MidiMessage event = MidiMessage(data, 	// spike data (float)
											sizeof(data), 	// number of bytes to use
											1000.0 	// timestamp (64-bit)
											);
			
			//event.setChannel(1);

			midiMessages.addEvent(data, sizeof(data), 5);
			//midiMessages.addEvent(event, 1);

			for (int n = 0; n < sizeof(data); n++) {
				data[n] = 2;
			}

			midiMessages.addEvent(data, sizeof(data), 10);

			for (int n = 0; n < sizeof(data); n++) {
				data[n] = 3;
			}

			midiMessages.addEvent(data, sizeof(data), 15);

			//midiMessages.addEvent(event, 5);

			//std::cout << "Midi buffer contains " << midiMessages.getNumEvents() << " events." << std::endl;

			accumulator = 0;
		}
		

	}

	
	

}
Ejemplo n.º 25
0
void test3()
{
    int bufferSize = 1000;
    char *buffer = AllocateAligned4( bufferSize );

// single message tests
    // empty message
    {
        memset( buffer, 0x74, bufferSize );
        OutboundPacketStream ps( buffer, bufferSize );
        ps << BeginMessage( "/no_arguments" )
            << EndMessage;
        assertEqual( ps.IsReady(), true );
        ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) );
        std::cout << m << "\n";\
    }

    TEST_PACK_UNPACK( "/a_bool", true, bool, AsBool );
    TEST_PACK_UNPACK( "/a_bool", false, bool, AsBool );
    TEST_PACK_UNPACK( "/a_bool", (bool)1, bool, AsBool );

    TEST_PACK_UNPACK0( "/nil", Nil, true, IsNil );
    TEST_PACK_UNPACK0( "/inf", Infinitum, true, IsInfinitum );

    TEST_PACK_UNPACK( "/an_int", (int32)1234, int32, AsInt32 );

    TEST_PACK_UNPACK( "/a_float", 3.1415926f, float, AsFloat );

    TEST_PACK_UNPACK( "/a_char", 'c', char, AsChar );

    TEST_PACK_UNPACK( "/an_rgba_color", RgbaColor(0x22334455), uint32, AsRgbaColor );

    TEST_PACK_UNPACK( "/a_midi_message", MidiMessage(0x7F), uint32, AsMidiMessage );

    TEST_PACK_UNPACK( "/an_int64", (int64)(0xFFFFFFFF), int64, AsInt64 );

    TEST_PACK_UNPACK( "/a_time_tag", TimeTag(0xFFFFFFFF), uint64, AsTimeTag );

    TEST_PACK_UNPACK( "/a_double", (double)3.1415926, double, AsDouble );

    // blob
    {
        char blobData[] = "abcd";
        memset( buffer, 0x74, bufferSize );
        OutboundPacketStream ps( buffer, bufferSize );
        ps << BeginMessage( "/a_blob" )
            << Blob( blobData, 4 )
            << EndMessage;
        assertEqual( ps.IsReady(), true );
        ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) );
        std::cout << m << "\n";

        const void *value;
        unsigned long size;
        m.ArgumentsBegin()->AsBlob( value, size );
        assertEqual( size, (unsigned long)4 );
        assertEqual( (memcmp( value, blobData, 4 ) == 0), true );
    }


    TEST_PACK_UNPACK( "/a_string", "hello world", const char*, AsString );

    TEST_PACK_UNPACK( "/a_symbol", Symbol("foobar"), const char*, AsSymbol );


    // nested bundles, and multiple messages in bundles...

    {
        memset( buffer, 0x74, bufferSize );
        OutboundPacketStream ps( buffer, bufferSize );
        ps << BeginBundle()
            << BeginMessage( "/message_one" ) << 1 << 2 << 3 << 4 << EndMessage
            << BeginMessage( "/message_two" ) << 1 << 2 << 3 << 4 << EndMessage
            << BeginMessage( "/message_three" ) << 1 << 2 << 3 << 4 << EndMessage
            << BeginMessage( "/message_four" ) << 1 << 2 << 3 << 4 << EndMessage
            << EndBundle;
        assertEqual( ps.IsReady(), true );
        ReceivedBundle b( ReceivedPacket(ps.Data(), ps.Size()) );
        std::cout << b << "\n";
    }
}