Skip to content

Commit 17166a1

Browse files
grandchildazeem
authored andcommitted
Refactoring/fields (#40)
* Rename output to blendMode in ColorMap * Rename BlendMode keys & Add Minimum & Absolute Difference * AVERAGE -> FIFTY_FIFTY * SUBTRACTIVE1/2 -> SUB_DEST_SRC/SUB_SRC_DEST * add MINIMUM * add ABSOLUTE_DIFFERENCE * Rename Channels/Source to AudioChannels/AudioSource * Channels -> AudioChannels * Source -> AudioSource * source/channel -> audioSource/audioChannel in SuperScope * source -> audioSource in Texer * Rename coordinate mode RECT to CARTESIAN * Rename various enums in ColorMap & BufferSave ColorMap: * ONBEATSEQUENTIAL -> ONBEAT_SEQUENTIAL * ONBEATRANDOM -> ONBEAT_RANDOM * (R+G+B)/2 -> CHANNEL_SUM_HALF * (R+G+B)/3 -> CHANNEL_AVERAGE BufferSave: * SAVERESTORE -> ALTERNATE_SAVE_RESTORE * RESTORESAVE -> ALTERNATE_RESTORE_SAVE Fix shader code indentation in ColorMap. * Add newlines at ends of various files * Rename channel to mode in ChannelShift
1 parent 2ce3dc8 commit 17166a1

21 files changed

+140
-129
lines changed

examples/JelloCube.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ addExamplePreset({
3939
},
4040
{
4141
"type": "ColorMap",
42-
"output": "REPLACE",
42+
"blendMode": "REPLACE",
4343
"key": "RED",
4444
"maps": [
4545
{
@@ -56,7 +56,7 @@ addExamplePreset({
5656
type: "EffectList",
5757
clearFrame: true,
5858
input: "IGNORE",
59-
output: "SUBTRACTIVE1",
59+
output: "SUB_DEST_SRC",
6060
components: [
6161
{
6262
type: "SuperScope",

examples/PillowFight.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ addExamplePreset({
3030
{
3131
"type": "DynamicMovement",
3232
"noGrid": true,
33-
"coord": "RECT",
33+
"coord": "CARTESIAN",
3434
"code": {
3535
"perPixel": "x=-x"
3636
}
@@ -76,7 +76,7 @@ addExamplePreset({
7676
{
7777
"type": "DynamicMovement",
7878
"noGrid": true,
79-
"coord": "RECT",
79+
"coord": "CARTESIAN",
8080
"code": {
8181
"perPixel": "y=-y"
8282
}
@@ -86,7 +86,7 @@ addExamplePreset({
8686
{
8787
"type": "ColorMap",
8888
"key": "RED",
89-
"output": "REPLACE",
89+
"blendMode": "REPLACE",
9090
"mapCycleMode": "SINGLE",
9191
"maps": [
9292
{
@@ -118,7 +118,7 @@ addExamplePreset({
118118
"enabled": true,
119119
"clearFrame": false,
120120
"input": "IGNORE",
121-
"output": "AVERAGE",
121+
"output": "FIFTY_FIFTY",
122122
"components": [
123123
{
124124
"type": "BufferSave",
@@ -128,7 +128,7 @@ addExamplePreset({
128128
},
129129
{
130130
"type": "DynamicMovement",
131-
"coord": "RECT",
131+
"coord": "CARTESIAN",
132132
"noGrid": true,
133133
"bFilter": false,
134134
"code": {
@@ -160,8 +160,8 @@ addExamplePreset({
160160
{
161161
"type": "ColorMap",
162162
"key": "RED",
163-
"output": "REPLACE",
164-
"mapCycleMode": "ONBEATSEQUENTIAL",
163+
"blendMode": "REPLACE",
164+
"mapCycleMode": "ONBEAT_SEQUENTIAL",
165165
"maps": [
166166
{
167167
"enabled": true,
@@ -231,8 +231,8 @@ addExamplePreset({
231231
{
232232
"type": "ColorMap",
233233
"key": "MAX",
234-
"output": "MULTIPLY",
235-
"mapCycleMode": "ONBEATSEQUENTIAL",
234+
"blendMode": "MULTIPLY",
235+
"mapCycleMode": "ONBEAT_SEQUENTIAL",
236236
"maps": [
237237
{
238238
"enabled": true,
@@ -259,11 +259,11 @@ addExamplePreset({
259259
},
260260
{
261261
"type": "DynamicMovement",
262-
"coord": "RECT",
262+
"coord": "CARTESIAN",
263263
"noGrid": true,
264264
"code": {
265265
"perPixel": "x=x-(1/6)"
266266
}
267267
}
268268
]
269-
});
269+
});

examples/RandomAnja.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ addExamplePreset({
5252
},
5353
"noGrid": true,
5454
"bFilter": true,
55-
"coord": "RECT",
55+
"coord": "CARTESIAN",
5656
"gridW": 0,
5757
"gridH": 0,
5858
"blend": false,
@@ -80,7 +80,7 @@ addExamplePreset({
8080
"perPoint": "x=x+xm;y=y+ym;"
8181
},
8282
"bFilter": true,
83-
"coord": "RECT",
83+
"coord": "CARTESIAN",
8484
"gridW": 0,
8585
"gridH": 0,
8686
"blend": false,
@@ -108,7 +108,7 @@ addExamplePreset({
108108
"perPoint": "x=x+xm;y=y+ym;"
109109
},
110110
"bFilter": true,
111-
"coord": "RECT",
111+
"coord": "CARTESIAN",
112112
"gridW": 0,
113113
"gridH": 0,
114114
"blend": false,

examples/SilkString.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ addExamplePreset({
140140
},
141141
{
142142
"type": "ColorMap",
143-
"output": "ADDITIVE",
143+
"blendMode": "ADDITIVE",
144144
"maps": [
145145
{
146146
"enabled": true,
@@ -151,4 +151,4 @@ addExamplePreset({
151151
]
152152
}
153153
]
154-
});
154+
});

examples/SuperscopeScience.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ addExamplePreset({
100100
"enabled": true
101101
}
102102
]
103-
});
103+
});

src/EffectList.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import TextureSetManager from "./webgl/TextureSetManager";
1212
export enum ELBlendMode {
1313
REPLACE = 1,
1414
MAXIMUM,
15-
AVERAGE,
15+
MINIMUM,
16+
FIFTY_FIFTY,
1617
ADDITIVE,
17-
SUBTRACTIVE1,
18-
SUBTRACTIVE2,
18+
SUB_DEST_SRC,
19+
SUB_SRC_DEST,
1920
MULTIPLY,
2021
MULTIPLY2,
2122
ADJUSTABLE,

src/analyser/AnalyserAdapter.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Channels, FloatArray } from "../utils";
1+
import { AudioChannels, FloatArray } from "../utils";
22

33
/**
44
* AnalyserAdapter adapts music data analysers so that it can be plugged into Webvs.
@@ -21,11 +21,11 @@ export default abstract class AnalyserAdapter {
2121
* Returns array of waveform values. Override and implement analyser code
2222
* @param channel channel for which waveform data will be returned
2323
*/
24-
public abstract getWaveform(channel?: Channels): FloatArray;
24+
public abstract getWaveform(channel?: AudioChannels): FloatArray;
2525

2626
/**
2727
* Returns array of spectrum values. Override and implement analyser code
2828
* @param channel channel for which spectrum data will be returned
2929
*/
30-
public abstract getSpectrum(channel?: Channels): FloatArray;
30+
public abstract getSpectrum(channel?: AudioChannels): FloatArray;
3131
}

src/analyser/WebAudioAnalyser.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Channels } from "../utils";
1+
import { AudioChannels } from "../utils";
22
import AnalyserAdapter from "./AnalyserAdapter";
33

44
interface IVisData {
@@ -193,12 +193,12 @@ export default class WebAudioAnalyser extends AnalyserAdapter {
193193
}
194194

195195
// Returns array of waveform values
196-
public getWaveform(channel: Channels = Channels.CENTER) {
196+
public getWaveform(channel: AudioChannels = AudioChannels.CENTER) {
197197
return this.visData[channel].waveform;
198198
}
199199

200200
// Returns array of spectrum values
201-
public getSpectrum(channel: Channels = Channels.CENTER) {
201+
public getSpectrum(channel: AudioChannels = AudioChannels.CENTER) {
202202
return this.visData[channel].spectrum;
203203
}
204204

src/misc/BufferSave.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export interface IBufferSaveOpts {
2626
enum BufferSaveAction {
2727
SAVE = 0,
2828
RESTORE,
29-
SAVERESTORE,
30-
RESTORESAVE,
29+
ALTERNATE_SAVE_RESTORE,
30+
ALTERNATE_RESTORE_SAVE,
3131
}
3232

3333
/**
@@ -65,8 +65,8 @@ export default class BufferSave extends Component {
6565

6666
public draw() {
6767
let currentAction;
68-
if (this.action === BufferSaveAction.SAVERESTORE ||
69-
this.action === BufferSaveAction.RESTORESAVE) {
68+
if (this.action === BufferSaveAction.ALTERNATE_SAVE_RESTORE ||
69+
this.action === BufferSaveAction.ALTERNATE_RESTORE_SAVE) {
7070
currentAction = this.nextAction;
7171
// toggle next action
7272
this.nextAction =
@@ -96,9 +96,9 @@ export default class BufferSave extends Component {
9696

9797
public updateAction() {
9898
this.action = BufferSaveAction[this.opts.action];
99-
if (this.action === BufferSaveAction.SAVERESTORE) {
99+
if (this.action === BufferSaveAction.ALTERNATE_SAVE_RESTORE) {
100100
this.nextAction = BufferSaveAction.SAVE;
101-
} else if (this.action === BufferSaveAction.RESTORESAVE) {
101+
} else if (this.action === BufferSaveAction.ALTERNATE_RESTORE_SAVE) {
102102
this.nextAction = BufferSaveAction.RESTORE;
103103
}
104104
}

src/render/SuperScope.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Component, {IContainer} from "../Component";
33
import CodeInstance from "../expr/CodeInstance";
44
import compileExpr, { ICompileResult } from "../expr/compileExpr";
55
import IMain from "../IMain";
6-
import { BlendMode, Channels, Color, parseColorNorm, Source, WebGLVarType } from "../utils";
6+
import { AudioChannels, AudioSource, BlendMode, Color, parseColorNorm, WebGLVarType } from "../utils";
77
import Buffer from "../webgl/Buffer";
88
import RenderingContext from "../webgl/RenderingContext";
99
import ShaderProgram from "../webgl/ShaderProgram";
@@ -59,11 +59,11 @@ export interface ISuperScopeOpts {
5959
/**
6060
* Channel for scope values. Default: `CENTER`
6161
*/
62-
channel: string;
62+
audioChannel: string;
6363
/**
6464
* Data source of scope value. Default: `SPECTRUM`
6565
*/
66-
source: string;
66+
audioSource: string;
6767
/**
6868
* Drawing mode for the scope. see [[SuperScopeDrawMode]]. Default: `LINES`
6969
*/
@@ -120,19 +120,20 @@ export default class SuperScope extends Component {
120120
public static componentName: string = "SuperScope";
121121
public static componentTag: string = "render";
122122
protected static optUpdateHandlers = {
123+
audioChannel: "updateAudioChannel",
124+
audioSource: "updateAudioSource",
123125
blendMode: "updateProgram",
124-
channel: "updateChannel",
125126
clone: "updateClones",
126127
code: [ "updateCode", "updateClones"],
127128
colors: "updateColors",
128129
cycleSpeed: "updateSpeed",
129130
drawMode: "updateDrawMode",
130-
source: "updateSource",
131131
thickness: "updateThickness",
132132
};
133133
protected static defaultOptions: ISuperScopeOpts = {
134+
audioChannel: "CENTER",
135+
audioSource: "SPECTRUM",
134136
blendMode: "REPLACE",
135-
channel: "CENTER",
136137
clone: 1,
137138
code: {
138139
init: "n=800",
@@ -143,7 +144,6 @@ export default class SuperScope extends Component {
143144
colors: ["#ffffff"],
144145
cycleSpeed: 0.01,
145146
drawMode: "LINES",
146-
source: "SPECTRUM",
147147
thickness: 1,
148148
};
149149

@@ -153,8 +153,8 @@ export default class SuperScope extends Component {
153153
private code: ISSCodeInstance[];
154154
private inited: boolean;
155155
private program: ShaderProgram<ISuperScopeShaderValues>;
156-
private source: Source;
157-
private channel: Channels;
156+
private audioSource: AudioSource;
157+
private audioChannel: AudioChannels;
158158
private drawMode: SuperScopeDrawMode;
159159
private veryThick: boolean;
160160
private colors: Color[];
@@ -168,13 +168,13 @@ export default class SuperScope extends Component {
168168

169169
public init() {
170170
this.updateDrawMode();
171-
this.updateSource();
171+
this.updateAudioSource();
172172
this.updateProgram();
173173
this.updateCode();
174174
this.updateClones();
175175
this.updateSpeed();
176176
this.updateColors();
177-
this.updateChannel();
177+
this.updateAudioChannel();
178178
this.updateThickness();
179179
this.listenTo(this.main, "resize", () => this.handleResize());
180180

@@ -221,10 +221,10 @@ export default class SuperScope extends Component {
221221

222222
const nPoints = Math.floor(code.n);
223223
let data;
224-
if (this.source === Source.SPECTRUM) {
225-
data = this.main.getAnalyser().getSpectrum(this.channel);
224+
if (this.audioSource === AudioSource.SPECTRUM) {
225+
data = this.main.getAnalyser().getSpectrum(this.audioChannel);
226226
} else {
227-
data = this.main.getAnalyser().getWaveform(this.channel);
227+
data = this.main.getAnalyser().getWaveform(this.audioChannel);
228228
}
229229
const dots = this.drawMode === SuperScopeDrawMode.DOTS;
230230
const bucketSize = data.length / nPoints;
@@ -466,12 +466,12 @@ export default class SuperScope extends Component {
466466
}
467467
}
468468

469-
private updateChannel() {
470-
this.channel = Channels[this.opts.channel];
469+
private updateAudioChannel() {
470+
this.audioChannel = AudioChannels[this.opts.audioChannel];
471471
}
472472

473-
private updateSource() {
474-
this.source = Source[this.opts.source];
473+
private updateAudioSource() {
474+
this.audioSource = AudioSource[this.opts.audioSource];
475475
}
476476

477477
private updateDrawMode() {

0 commit comments

Comments
 (0)