1 /*
2  * InstrumentFunctions.h - models for instrument-functions-tab
3  *
4  * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5  *
6  * This file is part of LMMS - https://lmms.io
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (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 GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with this program (see COPYING); if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301 USA.
22  *
23  */
24 
25 #ifndef INSTRUMENT_FUNCTIONS_H
26 #define INSTRUMENT_FUNCTIONS_H
27 
28 #include "JournallingObject.h"
29 #include "lmms_basics.h"
30 #include "AutomatableModel.h"
31 #include "TempoSyncKnobModel.h"
32 #include "ComboBoxModel.h"
33 
34 
35 class InstrumentTrack;
36 class NotePlayHandle;
37 
38 
39 
40 class InstrumentFunctionNoteStacking : public Model, public JournallingObject
41 {
42 	Q_OBJECT
43 
44 public:
45 	static const int MAX_CHORD_POLYPHONY = 13;
46 
47 private:
48 	typedef int8_t ChordSemiTones [MAX_CHORD_POLYPHONY];
49 
50 public:
51 	InstrumentFunctionNoteStacking( Model * _parent );
52 	virtual ~InstrumentFunctionNoteStacking();
53 
54 	void processNote( NotePlayHandle* n );
55 
56 
57 	virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent );
58 	virtual void loadSettings( const QDomElement & _this );
59 
nodeName()60 	inline virtual QString nodeName() const
61 	{
62 		return "chordcreator";
63 	}
64 
65 
66 	struct Chord
67 	{
68 	private:
69 		QString m_name;
70 		ChordSemiTones m_semiTones;
71 		int m_size;
72 
73 	public:
ChordChord74 		Chord() : m_size( 0 ) {}
75 
76 		Chord( const char * n, const ChordSemiTones & semi_tones );
77 
sizeChord78 		int size() const
79 		{
80 			return m_size;
81 		}
82 
isScaleChord83 		bool isScale() const
84 		{
85 			return size() > 6;
86 		}
87 
isEmptyChord88 		bool isEmpty() const
89 		{
90 			return size() == 0;
91 		}
92 
93 		bool hasSemiTone( int8_t semiTone ) const;
94 
lastChord95 		int8_t last() const
96 		{
97 			return m_semiTones[size() - 1];
98 		}
99 
getNameChord100 		const QString & getName() const
101 		{
102 			return m_name;
103 		}
104 
105 		int8_t operator [] ( int n ) const
106 		{
107 			return m_semiTones[n];
108 		}
109 	};
110 
111 
112 	struct ChordTable : public QVector<Chord>
113 	{
114 	private:
115 		ChordTable();
116 
117 		struct Init
118 		{
119 			const char * m_name;
120 			ChordSemiTones m_semiTones;
121 		};
122 
123 		static Init s_initTable[];
124 
125 	public:
getInstanceChordTable126 		static const ChordTable & getInstance()
127 		{
128 			static ChordTable inst;
129 			return inst;
130 		}
131 
132 		const Chord & getByName( const QString & name, bool is_scale = false ) const;
133 
getScaleByNameChordTable134 		const Chord & getScaleByName( const QString & name ) const
135 		{
136 			return getByName( name, true );
137 		}
138 
getChordByNameChordTable139 		const Chord & getChordByName( const QString & name ) const
140 		{
141 			return getByName( name, false );
142 		}
143 	};
144 
145 
146 private:
147 	BoolModel m_chordsEnabledModel;
148 	ComboBoxModel m_chordsModel;
149 	FloatModel m_chordRangeModel;
150 
151 
152 	friend class InstrumentFunctionNoteStackingView;
153 
154 } ;
155 
156 
157 
158 
159 class InstrumentFunctionArpeggio : public Model, public JournallingObject
160 {
161 	Q_OBJECT
162 public:
163 	enum ArpDirections
164 	{
165 		ArpDirUp,
166 		ArpDirDown,
167 		ArpDirUpAndDown,
168 		ArpDirDownAndUp,
169 		ArpDirRandom,
170 		NumArpDirections
171 	} ;
172 
173 	InstrumentFunctionArpeggio( Model * _parent );
174 	virtual ~InstrumentFunctionArpeggio();
175 
176 	void processNote( NotePlayHandle* n );
177 
178 
179 	virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent );
180 	virtual void loadSettings( const QDomElement & _this );
181 
nodeName()182 	inline virtual QString nodeName() const
183 	{
184 		return "arpeggiator";
185 	}
186 
187 
188 private:
189 	enum ArpModes
190 	{
191 		FreeMode,
192 		SortMode,
193 		SyncMode
194 	} ;
195 
196 	BoolModel m_arpEnabledModel;
197 	ComboBoxModel m_arpModel;
198 	FloatModel m_arpRangeModel;
199 	FloatModel m_arpCycleModel;
200 	FloatModel m_arpSkipModel;
201 	FloatModel m_arpMissModel;
202 	TempoSyncKnobModel m_arpTimeModel;
203 	FloatModel m_arpGateModel;
204 	ComboBoxModel m_arpDirectionModel;
205 	ComboBoxModel m_arpModeModel;
206 
207 
208 	friend class InstrumentTrack;
209 	friend class InstrumentFunctionArpeggioView;
210 
211 } ;
212 
213 
214 #endif
215