1 /*
2     MidiLearn.h
3 
4     Copyright 2016-2020 Will Godfrey
5 
6     This file is part of yoshimi, which is free software: you can redistribute
7     it and/or modify it under the terms of the GNU Library General Public
8     License as published by the Free Software Foundation; either version 2 of
9     the License, or (at your option) any later version.
10 
11     yoshimi is distributed in the hope that it will be useful, but WITHOUT ANY
12     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13     FOR A PARTICULAR PURPOSE.   See the GNU General Public License (version 2 or
14     later) for more details.
15 
16     You should have received a copy of the GNU General Public License along with
17     yoshimi; if not, write to the Free Software Foundation, Inc., 51 Franklin
18     Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 
20 */
21 
22 #ifndef MIDILEARN_H
23 #define MIDILEARN_H
24 
25 #include "globals.h"
26 
27 #include <list>
28 #include <string>
29 
30 #include "Interface/InterChange.h"
31 #include "Interface/Data2Text.h"
32 #include "Interface/Text2Data.h"
33 
34 class XMLwrapper;
35 class SynthEngine;
36 class DataText;
37 class TextData;
38 
39 using std::string;
40 using std::list;
41 
42 class MidiLearn : private DataText, TextData
43 {
44     public:
45         MidiLearn(SynthEngine *_synth);
46         ~MidiLearn();
47         void add2XML(XMLwrapper *xml);
48         void getfromXML(XMLwrapper *xml);
49         CommandBlock data;//commandData;
50 
51 /*        struct Control{
52             unsigned char type = 0;
53             unsigned char control = 0;
54             unsigned char part = 0;
55             unsigned char kit = 0;
56             unsigned char engine = 0;
57             unsigned char insert = 0;
58             unsigned char parameter = 0;
59             unsigned char offset = 0;
60             unsigned char miscmsg = 0;
61         };*/
62 
63         //Control data;
64 
65         struct LearnBlock{
66             unsigned short int CC = 0;
67             unsigned char chan = 0;
68             unsigned char min_in = 0;
69             unsigned char max_in = 0;
70             unsigned char status = 0; // up to here must be specified on input
71             int min_out = 0; // defined programmatically
72             int max_out = 0; // defined programmatically
73             CommandBlock frame; // controller to learn
74         };
75         bool learning;
76 
77         void setTransferBlock(CommandBlock *getData);
78 
79         bool runMidiLearn(int _value, unsigned short int CC, unsigned char chan, bool in_place);
80         bool writeMidi(CommandBlock *putData, bool in_place);
81 
82         int findSize();
83         void listLine(int lineNo);
84         void listAll(list<string>& msg_buf);
85         bool remove(int itemNumber);
86         void generalOperations(CommandBlock *getData);
87         bool insertMidiListData(XMLwrapper *xml);
88         bool loadList(const string& name);
89         bool extractMidiListData(bool full,  XMLwrapper *xml);
90         void updateGui(int opp = 0);
91 
92 
93     private:
94         list<LearnBlock> midi_list;
95         string learnedName;
96         CommandBlock learnTransferBlock;
97         int findEntry(list<LearnBlock> &midi_list, int lastpos, unsigned short int CC, unsigned char chan, LearnBlock *block, bool show);
98         string findName(list<LearnBlock>::iterator it);
99         void insertLine(unsigned short int CC, unsigned char chan);
100         bool saveList(const string& name);
101         SynthEngine *synth;
102         void writeToGui(CommandBlock *putData);
103 };
104 
105 #endif
106