1 /*!
2  * @file midiworker.cpp
3  * @brief Implements the MIDI worker module base 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 #include <cmath>
25 #include "midiworker.h"
26 
27 
MidiWorker()28 MidiWorker::MidiWorker()
29 {
30     enableNoteIn = true;
31     enableNoteOff = false;
32     enableVelIn = true;
33     trigByKbd = false;
34     gotKbdTrig = false;
35     restartByKbd = false;
36     trigLegato = false;
37     for (int l1 = 0; l1 < 2; l1++) {
38         rangeIn[l1] = (l1) ? 127 : 0;
39         indexIn[l1] = (l1) ? 127 : 0;
40     }
41 
42     queueTempo = 100.0;
43     ccnumber = 74;
44     portOut = 0;
45     channelOut = 0;
46     chIn = OMNI;
47     ccnumberIn = 74;
48     isMuted = false;
49     isMutedDefer = false;
50     deferChanges = false;
51     reverse = false;
52     pingpong = false;
53     backward = false;
54     reflect = false;
55     seqFinished = false;
56     restartFlag = false;
57     triggerMode = 0;
58     enableLoop = true;
59     curLoopMode = 0;
60     noteCount = 0;
61     nextTick = 0;
62     grooveTick = 0;
63     newGrooveTick = 0;
64     grooveVelocity = 0;
65     grooveLength = 0;
66     framePtr = 0;
67     nPoints = 1;
68 
69     dataChanged = false;
70     needsGUIUpdate = false;
71     parChangesPending = false;
72 
73 }
74 
setMuted(bool on)75 void MidiWorker::setMuted(bool on)
76 {
77     isMutedDefer = on;
78     if (deferChanges) {
79         parChangesPending = true;
80     }
81     else isMuted = on;
82 
83     needsGUIUpdate = false;
84 }
85 
clip(int value,int min,int max,bool * outOfRange)86 int MidiWorker::clip(int value, int min, int max, bool *outOfRange)
87 {
88     int tmp = value;
89 
90     *outOfRange = false;
91     if (tmp > max) {
92         tmp = max;
93         *outOfRange = true;
94     } else if (tmp < min) {
95         tmp = min;
96         *outOfRange = true;
97     }
98     return(tmp);
99 }
100