Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Leap Motion Development Essentials

You're reading from  Leap Motion Development Essentials

Product type Book
Published in Oct 2013
Publisher Packt
ISBN-13 9781849697729
Pages 106 pages
Edition 1st Edition
Languages
Author (1):
Mischa Spiegelmock Mischa Spiegelmock
Profile icon Mischa Spiegelmock

Refactoring for multithreading


Before continuing further on, perhaps it would be a good time to refactor our virtual MIDI device output functionality into its own class, as the MIDI output routines with the attendant threading code should be encapsulated for maintaining some semblance of clean program structure.

namespace leapmidi {
class Device {
public:
    Device();
    ~Device();
    void init();
    void queueControlMessage(midi_control_index controlIndex, midi_control_value controlValue);

We'll go ahead and create a leapmidi::Device class. Users of our class construct a new Device class and call init() to set up the MIDI virtual device, and then send MIDI control messages using queueControlMessage().

protected:
    void initPacketList();
    void createDevice();

Our earlier MIDI virtual device setup code can go in here.

    pthread_t messageQueueThread;
    void *messageSendingThreadEntry();

This function will be called when our MIDI output thread (kept track of by messageQueueThread) begins...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}