1 /*!
2  * @file midiworker.h
3  * @brief Member definitions for the MidiWorker class.
4  *
5  *
6  *      Copyright 2009 - 2017 <qmidiarp-devel@lists.sourceforge.net>
7  *
8  *      This program is free software; you can redistribute it and/or modify
9  *      it under the terms of the GNU General Public License as published by
10  *      the Free Software Foundation; either version 2 of the License, or
11  *      (at your option) any later version.
12  *
13  *      This program is distributed in the hope that it will be useful,
14  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *      GNU General Public License for more details.
17  *
18  *      You should have received a copy of the GNU General Public License
19  *      along with this program; if not, write to the Free Software
20  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  *      MA 02110-1301, USA.
22  *
23  */
24 
25 #ifndef MIDIWORKER_H
26 #define MIDIWORKER_H
27 
28 #include "main.h"
29 #include <cstdlib>
30 #include <cstdio>
31 
32 
33 /*! @brief MIDI worker base class for QMidiArp modules.
34  *
35  * The three Midi Module classes inherit from this class. It provides common
36  * input output settings variables and some other small functions that all
37  * modules have in common
38 */
39 class MidiWorker {
40 
41   public:
42     double queueTempo;  /*!< current tempo of the transport, not in use here */
43     int chIn;           /**< Channel of input events */
44     int indexIn[2]; /*!< Note range filter 0: lower, 1: upper limit, set by InOutBox */
45     int rangeIn[2]; /*!< Velocity range filter 0: lower, 1: upper limit, set by InOutBox */
46     bool enableNoteIn;
47     bool enableNoteOff;
48     bool enableVelIn;
49     bool restartByKbd;
50     bool trigByKbd;
51     bool trigLegato; /*!< If True, trigger and restart upon legato input notes as well */
52     int triggerMode; /*!< Current Trigger mode index */
53     bool enableLoop; /*!< Enables looping of sequence or wave, determined by the loopMode */
54     bool gotKbdTrig; /*!< Set by MidiWorker::handleEvent() when the module was triggered by a new keyboard stroke */
55     bool restartFlag; /*!< Signals frameptr reset on next getNextFrame() call */
56     bool backward;       /*!< True when the sequence should start backward */
57     bool pingpong;      /*!< True when the play direction should alternate */
58     bool reflect;      /*!< True when the current play direction will change at the next reflect point */
59     bool reverse;       /*!< True when the current play direction is backwards */
60     int curLoopMode;    /*!< Local storage of the currently active Loop mode */
61     bool seqFinished;   /*!< When True, all output events are muted, used when NOTE OFF is received */
62     bool deferChanges;  /*!< When True, defer parameter changes to pattern end */
63     bool parChangesPending;    /*!< set when deferChanges is set and a parameter is changed */
64     int portOut;    /*!< MIDI output port number */
65     int channelOut; /*!< MIDI output channel */
66     int ccnumber;   /*!< MIDI Controller CC number to output */
67     int ccnumberIn;
68     bool isMuted;   /*!< Global mute state */
69     bool isMutedDefer;   /*!< Deferred Global mute state */
70     int nextTick; /*!< Holds the next tick at which note events will be played out */
71     int noteCount;      /*!< The number of notes in the MidiWorker::notes buffer */
72     int newGrooveTick, grooveTick, grooveVelocity, grooveLength;
73     int framePtr;       /*!< position of the currently output frame in sequence/wave/pattern */
74     int nPoints;        /*!< Number of steps in pattern or sequence or wave */
75     bool dataChanged; /*!< Flag set to true by recording loop and queried by InOutBox::updateDisplay() */
76     bool needsGUIUpdate; /*!< Flag set to true when MidiWorker members changed and queried by InOutBox::updateDisplay() */
77 
78   public:
79     MidiWorker();
80 /*! @brief sets MidiWorker::isMuted, which is checked by
81  * Engine and which suppresses data output globally if set to True.
82  *
83  * @param on Set to True to suppress data output to the Driver
84  */
85     virtual void setMuted(bool on);
86 
87 /*! @brief  sets MidiWorker::deferChanges, which will cause a
88  * parameter changes only at pattern end.
89  *
90  * @param on Set to True to defer changes to pattern end
91  */
updateDeferChanges(bool on)92     virtual void updateDeferChanges(bool on) { deferChanges = on; }
93 /**
94  * @brief allows forcing an integer value within the
95  * specified range (clip).
96  *
97  * @param value The value to be checked
98  * @param min The minimum allowed return value
99  * @param max The maximum allowed return value
100  * @param outOfRange Is set to True if value was outside min|max range
101  * @return The value clipped within the range
102  */
103     virtual int clip(int value, int min, int max, bool *outOfRange);
getFramePtr()104     virtual int getFramePtr() { return framePtr; }
105     virtual void getNextFrame(int tick) = 0;
106 };
107 
108 #endif
109