Giter VIP home page Giter VIP logo

qmidi's Introduction

QMidi

Qt based library that communicate with MIDI

version license C/C++ CI

Features

  • Send and receive MIDI Messages
  • Easily open Virtual MIDI ports on Unix based machines

Building & Integrating

It is a CMake project. you can either build it using:

cmake -S . -B build
cmake --build build

Or use it as a subdirectory

add_subdirectory(path/to/Qmidi EXCLUDE_FROM_ALL)
target_link_libraries(mytarget PUBLIC QMidi)

Usage

#include <QApplication>
#include <QDebug>
#include <QMidi>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
  
  	// The QMidi object represents a pair of in & out midi ports
  	// you can create as many as you wish if you want more ports.
  	
  	// The default constructor chooses the first available API for your OS
  	// and should be ready to use in most cases
  	QMidi midi;
  
  	// If you're on a unix-base system and want to use an alternative API
  	// say jackd, you can explicitly set it like so:
  	midi.setApi(QMidiApi::JACK);
  
  	// You can query available APIs using:
  	for(auto api : QMidi::availableApi())
      	qDebug() << api;
  
  	// You can also set a custom client name, so you're application
  	// has the correct name displayed
  	midi.setClientName("Super Midi 3000");
  
  	// After each call, you can check whether there's been an error using:
  	if(midi.hasError())
        qWarning() << midi.error() << midi.errorString();
  
  	// You can query available MIDI interfaces using the following:
  	for(const auto& i : midi.availableInterfaces())
    {
      	qDebug() << "Index:" << i.index();
      	qDebug() << "Name:" << i.name();
      	qDebug() << "API:" << i.api();
      	qDebug() << "Directions (in/out):" << i.directions();
      
      	// Or simply
      	qDebug() << i;
    }
  
  	// Say the first interface is the one you want to use
  	// you need to set it using:
  	const auto& i = midi.availableInterfaces().constFirst();
  	midi.setInputInterface(i);
  	midi.setOutputInterface(i);
  
  	// Now you can open the midi ports and start using them
  	midi.open();
  
  	// Alternatively, on unix-based system you can open
  	// Virtual ports that will allow your application to
    // be detected by others as MIDI interface
  	midi.openVirtual("My Virtual Port");
  
  	// From there you can use the set of signals and slots to
  	// send and recieve midi data
  
  	// you can get the raw message and do the processing yourself
  	QObject::connect(&midi, &QMidi::messageReceived, [](const QByteArray& data)
    {
				qDebug() << "Message received:" << data;
    });
  
  	// but you can get all the different message types with the appropriate signals
  	QObject::connect(&midi, &QMidi::midiNoteOff, [](quint8 chan, quint8 note, quint8 vel)
    {
      	qDebug() << "Note On received on channel" << chan;
      	qDebug() << "Node:" << static_cast<QMidiNode>(note);
      	qDebug() << "Velocity:" << vel;
    })
      
    // You can also send MIDI messages using similarly named slots.
    // Both raw message and individual message type slots are available:
    midi.sendNoteOn(0, QMidiNode::ASharp_5, 127);
  	midi.sendNoteOff(0, QMidiNode::ASharp_5, 0);
  
  	// All those methods are slots for easily connect with other Qt objects
  	// For example, you can do an easy pass-through with the following:
  	QObject::connect(&midi, &QMidi::messageReceived,
                     &midi, &QMidi::sendMessage);
  	
    a.exec();
}

qmidi's People

Contributors

nicog60 avatar philius avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.