aboutsummaryrefslogtreecommitdiff
path: root/polarizer/polarizerBi.cpp
blob: e270f557bf65e0290500f3d846ddbea3f785394b (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
/*---------------------------------------------------------------

   © 2001, Marcberg Soft und Hard GmbH, All Rights Perversed

---------------------------------------------------------------*/

#ifndef __polarizer
#include "polarizer.hpp"
#endif

#include <stdio.h>

//-----------------------------------------------------------------------------------------
// Destroy FX infos

long Polarizer::getVendorVersion() {
	return 1; }

bool Polarizer::getErrorText(char *text) {
	strcpy (text, "We're not gonna to make it.");	// max 256 char
	return true; }

bool Polarizer::getVendorString(char *text) {
	strcpy (text, "Destroy FX");	// a string identifying the vendor (max 64 char)
	return true; }

bool Polarizer::getProductString(char *text) {
	// a string identifying the product name (max 64 char)
	strcpy (text, "Super Destroy FX bipolar VST plugin pack");
	return true; }

//-----------------------------------------------------------------------------------------
Polarizer::~Polarizer()
{
	if (programName)
		delete[] programName;
}

//-----------------------------------------------------------------------------------------
void Polarizer::setProgramName(char *name)
{
	strcpy(programName, name);
}

//-----------------------------------------------------------------------------------------
void Polarizer::getProgramName(char *name)
{
	strcpy(name, programName);
}

//-----------------------------------------------------------------------------------------
void Polarizer::setParameter(long index, float value)
{
	switch (index)
	{
		case kSkip :    fSkip = value;		break;
		case kAmount :  fAmount = value;	break;
		case kImplode : fImplode = value;	break;
	}
}

//-----------------------------------------------------------------------------------------
float Polarizer::getParameter(long index)
{
	switch (index)
	{
		default:
		case kSkip :    return fSkip;
		case kAmount :  return fAmount;
		case kImplode : return fImplode;
	}
}

//-----------------------------------------------------------------------------------------
// titles of each parameter

void Polarizer::getParameterName(long index, char *label)
{
	switch (index)
	{
		case kSkip :    strcpy(label, "  leap  ");	break;
		case kAmount :  strcpy(label, "polarize");	break;
		case kImplode : strcpy(label, "implode");	break;
	}
}

//-----------------------------------------------------------------------------------------
// numerical display of each parameter's gradiations

void Polarizer::getParameterDisplay(long index, char *text)
{
	switch (index)
	{
		case kSkip :
			sprintf(text, "%ld", leapScaled(fSkip));
			break;
		case kAmount :
			sprintf(text, "%.3f", fAmount);
			break;
		case kImplode :
			if (fImplode >= 0.03f) strcpy(text, "yes");
			else strcpy(text, "no");
			break;
	}
}

//-----------------------------------------------------------------------------------------
// unit of measure for each parameter

void Polarizer::getParameterLabel(long index, char *label)
{
	switch (index)
	{
		case kSkip :
			if (leapScaled(fSkip) == 1) strcpy(label, "sample ");
			else strcpy(label, "samples");
			break;
		case kAmount :  strcpy(label, "amount");	break;
		case kImplode : strcpy(label, "      ");	break;
	}
}

//-----------------------------------------------------------------------------------------
// this is for getting the scalar value amp for the current sample

float Polarizer::processSampleAmp()
{
	switch (state)
	{
		case unaffected:	// nothing much happens in this section
			if (--unaffectedSamples <= 0)	// go to polarized when the leap is done
				state = polarized;
			return 1.0f;
			break;
			// end unaffected

		case polarized:
			state = unaffected;	// go right back to unaffected
			// but first figure out how long unaffected will last this time
			unaffectedSamples = leapScaled(fSkip);
			return (0.5f - fAmount) * 2.0f;	// this is the polarization scalar
			break;
			// end polarized

		default : return 1.0f;
	}
}

//-----------------------------------------------------------------------------------------
// this is for calculating & sending the current sample output value to the output stream

float Polarizer::processOutValue(float amp, float in)
{
  float out = (in * amp);	// if implode is off, just do the regular polarizing thing

	if (fImplode >= 0.03f)	// if it's on, then implode the audio signal
	{
		if (out > 0.0f)	// invert the sample between 1 & 0
			out = 1.0f - out;
		else	// invert the sample between -1 & 0
			out = -1.0f - out;
	}

	return out;
}