summaryrefslogtreecommitdiff
path: root/muse_qt4_evolution/synti/zynaddsubfx/Misc/Master.h
blob: 51feabdd0cfc54eab28668db077ad56cf216a961 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
  ZynAddSubFX - a software synthesizer
 
  Master.h - It sends Midi Messages to Parts, receives samples from parts,
             process them with system/insertion effects and mix them
  Copyright (C) 2002-2005 Nasca Octavian Paul
  Author: Nasca Octavian Paul

  This program is free software; you can redistribute it and/or modify
  it under the terms of version 2 of the GNU General Public License 
  as published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License (version 2) for more details.

  You should have received a copy of the GNU General Public License (version 2)
  along with this program; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA

*/

#ifndef MASTER_H
#define MASTER_H

#include "../globals.h"
#include "../Effects/EffectMgr.h"
#include "Part.h"
#include "../Output/Recorder.h"
#include "Microtonal.h"

#include "Bank.h"
#include "Dump.h"
#include "../Seq/Sequencer.h"
#include "XMLwrapper.h"

extern Dump dump;
class Master{
    public:    
	Master();
	~Master();

	//saves all settings to a XML file
	//returns 0 for ok  or <0 if there is an error
	int saveXML(char *filename);

	//this adds the parameters to the XML data
	void add2XML(XMLwrapper *xml);

	void defaults();


	//loads all settings from a XML file
	//returns 0 for ok or -1 if there is an error
	int loadXML(char *filename);
	void applyparameters();

	void getfromXML(XMLwrapper *xml);
	
	//get all data to a newly allocated array (used for VST)
	//returns the datasize
	int getalldata(char **data);
	//put all data from the *data array to zynaddsubfx parameters (used for VST)
	void putalldata(char *data,int size);



	//Midi IN
	void NoteOn(unsigned char chan,unsigned char note,unsigned char velocity);
	void NoteOff(unsigned char chan,unsigned char note);
	void SetController(unsigned char chan,unsigned int type,int par);
	//void NRPN...
	
	
        void ShutUp();
	int shutup;

	//Audio Output
	void AudioOut(REALTYPE *outl,REALTYPE *outr);
	//Audio Output (for callback mode). This allows the program to be controled by an external program
	void GetAudioOutSamples(int nsamples, REALTYPE *outl,REALTYPE *outr);


	void partonoff(int npart,int what);
	
	//parts
	Part *part[NUM_MIDI_PARTS];
		
	//parameters
	unsigned char Pvolume;
	unsigned char Pkeyshift;
	unsigned char Psysefxvol[NUM_SYS_EFX][NUM_MIDI_PARTS];
	unsigned char Psysefxsend[NUM_SYS_EFX][NUM_SYS_EFX];
	
	//parameters control
	void setPvolume(char Pvolume_);
	void setPkeyshift(char Pkeyshift_);
	void setPsysefxvol(int Ppart,int Pefx,char Pvol);
	void setPsysefxsend(int Pefxfrom,int Pefxto,char Pvol);

	//effects
	EffectMgr *sysefx[NUM_SYS_EFX];//system
	EffectMgr *insefx[NUM_INS_EFX];//insertion
//	void swapcopyeffects(int what,int type,int neff1,int neff2);

	//HDD recorder
	Recorder HDDRecorder; 

	//part that's apply the insertion effect; -1 to disable
    	short int Pinsparts[NUM_INS_EFX];
    
	//peaks for VU-meter
	void vuresetpeaks();
	REALTYPE vuoutpeakl,vuoutpeakr,vumaxoutpeakl,vumaxoutpeakr,vurmspeakl,vurmspeakr;
	int vuclipped;
	
	//peaks for part VU-meters
	REALTYPE vuoutpeakpart[NUM_MIDI_PARTS];
	unsigned char fakepeakpart[NUM_MIDI_PARTS];//this is used to compute the "peak" when the part is disabled

	Controller ctl;
	int swaplr;//1 if L and R are swapped

	//Sequencer
	Sequencer seq;
	
	//other objects 
	Microtonal microtonal;
	Bank bank;
	
	FFTwrapper *fft;
      volatile bool busy;     // if true,  is busy and cannot accept
                              // events or deliver data
      void lock()   { busy = true; }
      void unlock() { busy = false; }

    private:
	REALTYPE volume;	
	REALTYPE sysefxvol[NUM_SYS_EFX][NUM_MIDI_PARTS];
	REALTYPE sysefxsend[NUM_SYS_EFX][NUM_SYS_EFX];

	//Temporary mixing samples for part samples which is sent to system effect
        REALTYPE *tmpmixl;
        REALTYPE *tmpmixr;


	int keyshift;

	//Audio Output samples (if it used GetAudioOutSamples - eg. for Jack output; elsewhere is unused)
	REALTYPE *audiooutl;
	REALTYPE *audiooutr;
	
	int ksoundbuffersamples;  // number of valid samples in audiooutr/l
	REALTYPE ksoundbuffersamplelow;//this is used for resampling (eg. if Jack samplerate!= SAMPLE_RATE)
	REALTYPE oldsamplel,oldsampler;//this is used for resampling

	//Theese are called by the NoteOn, NoteOff,SetController (which are from external sources like MIDI, Virtual Keyboard)
	//and are called by internal parts of the program (like sequencer)
	void noteon(unsigned char chan,unsigned char note,unsigned char velocity);
	void noteoff(unsigned char chan,unsigned char note);
	void setcontroller(unsigned char chan,unsigned int type,int par);
};


#endif