1 /*  SpiralSynth
2  *  Copyleft (C) 2000 David Griffiths <dave@pawfal.org>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 
19 #include "Sequencer.h"
20 
Sequencer()21 Sequencer::Sequencer() :
22 m_Playing(false),
23 m_Step(0),
24 m_NCalls(10),
25 m_Count(0),
26 m_ArpType(1),
27 m_Octave(3),
28 m_Length(15),
29 m_Arp(false),
30 m_ArpNotes(2),
31 m_ArpPos(0),
32 m_OffsetNote(0),
33 m_OffsetOct(0)
34 {
35 	for(int n=0; n<191; n++) m_EventList[n]=false;
36 	for(int n=0; n<16; n++) m_TimeList[n]=0.5f;
37 	for(int n=0; n<12; n++) m_FreqList[n]=0.0f;
38 	for(int n=0; n<16; n++) m_VolList[n]=1.0f;
39 }
40 
Trigger(int oct,int note)41 void Sequencer::Trigger(int oct, int note)
42 {
43 	m_OffsetOct=oct;
44 	m_OffsetNote=note;
45 }
46 
GetSeqNote(float & note,int & oct,int & key)47 bool Sequencer::GetSeqNote(float &note, int &oct, int &key)
48 {
49 	if (!m_Playing) return false;
50 
51 	int Start=m_Step*12;
52 	bool e=false;
53 	m_Count++;
54 	if (m_Count>m_NCalls)
55 	{
56 		m_Count=0;
57 		// check current notes
58 		for (int n=0; n<12; n++)
59 		{
60 			// is an event sequenced?
61 			if (m_EventList[Start+n]==true)
62 			{
63 				e=true;
64 				oct=m_Octave+m_OffsetOct;
65 				key=n+m_OffsetNote;
66 
67 cerr<<"Offset="<<m_OffsetOct<<" "<<m_OffsetNote<<endl;
68 cerr<<"result="<<oct<<" "<<key<<endl;
69 
70 				if (oct<0) oct=0;
71 				if (oct>5) oct=5;
72 				if (key<0) key=0;
73 				if (key>11) key=11;
74 
75 				note=NoteTable[oct][key];
76 			}
77 
78 		}
79 
80 		m_Step++;
81 		if (m_Step>m_Length)
82 		{
83 			m_Step=0;
84 
85 			if (m_Arp)
86 			{
87 				if (m_ArpType==1)
88 				{
89 					m_ArpPos++;
90 					if (m_ArpPos>m_ArpNotes) m_ArpPos=0;
91 				}
92 				else
93 				{
94 					m_ArpPos--;
95 					if (m_ArpPos<0) m_ArpPos=m_ArpNotes;
96 				}
97 			}
98 		}
99 	}
100 	return e;
101 }
102