Skip to content

Commit 2e431bf

Browse files
author
FMS-Cat
committed
aesthetics: offset time by 16 beat
1 parent aac19f3 commit 2e431bf

File tree

4 files changed

+54
-20
lines changed

4 files changed

+54
-20
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @type {import('../automaton/node_modules/@fms-cat/automaton/types').SerializedAutomaton}
3+
*/
4+
const data = require( './src/automaton.json' );
5+
6+
const newData = JSON.parse( JSON.stringify( data ) );
7+
8+
const bpm = 180.0;
9+
const beat = 60.0 / bpm;
10+
11+
const shift = 16.0 * beat;
12+
13+
newData.channels.forEach( ( [ name, channel ] ) => {
14+
channel.items.forEach( ( item ) => {
15+
item.time += shift;
16+
} );
17+
} );
18+
19+
console.log( JSON.stringify( newData ) );

src/automaton.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/music/Music.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,26 @@ import { GLCatBuffer, GLCatProgram, GLCatTransformFeedback } from '@fms-cat/glca
33
import { MUSIC_BPM } from '../config';
44
import { SamplesManager } from './SamplesManager';
55
import { audio } from '../globals/music';
6+
import { binarySearch } from '@fms-cat/automaton';
67
import { gl, glCat } from '../globals/canvas';
78
import { injectCodeToShader } from '../utils/injectCodeToShader';
89
import { randomTextureStatic } from '../globals/randomTexture';
910
import musicVert from './music.vert';
1011

1112
const discardFrag = '#version 300 es\nvoid main(){discard;}';
1213

14+
const sectionResets = [
15+
16.0,
16+
80.0,
17+
144.0,
18+
208.0,
19+
272.0,
20+
336.0,
21+
400.0,
22+
464.0,
23+
1E9,
24+
].map( ( v ) => v * 60.0 / MUSIC_BPM );
25+
1326
export abstract class Music {
1427
public isPlaying: boolean;
1528
public time: number;
@@ -128,7 +141,10 @@ export abstract class Music {
128141

129142
const beatLength = 60.0 / MUSIC_BPM;
130143
const barLength = 240.0 / MUSIC_BPM;
131-
const sixteenBarLength = 3840.0 / MUSIC_BPM;
144+
145+
const sectionReset = binarySearch( sectionResets, time );
146+
const sectionBegin = sectionResets[ sectionReset ];
147+
const sectionLength = sectionResets[ sectionReset + 1 ] - sectionBegin;
132148

133149
program.attribute( 'off', this.__bufferOff, 1 );
134150
program.uniform( 'bpm', '1f', MUSIC_BPM );
@@ -139,15 +155,15 @@ export abstract class Music {
139155
'4f',
140156
beatLength,
141157
barLength,
142-
sixteenBarLength,
158+
sectionLength,
143159
1E16
144160
);
145161
program.uniform(
146162
'_timeHead',
147163
'4f',
148164
time % beatLength,
149165
time % barLength,
150-
time % sixteenBarLength,
166+
( time - sectionBegin ) % sectionLength,
151167
time,
152168
);
153169

src/music/music.vert

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ const float PI = 3.14159265359;
88
const float TAU = 6.28318530718;
99
const float BPM = 180.0;
1010
const float BEAT = 60.0 / BPM;
11-
const float SECTION_BEGIN = 0.0 * BEAT;
12-
const float SECTION_NEURO = 128.0 * BEAT;
13-
const float SECTION_WHOA = 256.0 * BEAT;
14-
const float SECTION_PORTER_FUCKING_ROBINSON = 320.0 * BEAT;
15-
const float SECTION_AAAA = 384.0 * BEAT;
16-
const float SECTION_PSY = 448.0 * BEAT;
11+
const float SECTION_BEGIN = 16.0 * BEAT;
12+
const float SECTION_NEURO = 144.0 * BEAT;
13+
const float SECTION_WHOA = 272.0 * BEAT;
14+
const float SECTION_PORTER_FUCKING_ROBINSON = 336.0 * BEAT;
15+
const float SECTION_AAAA = 400.0 * BEAT;
16+
const float SECTION_PSY = 464.0 * BEAT;
1717

1818
#define saturate(i) clamp(i, 0.,1.)
1919
#define aSaturate(i) clamp((i),-1.,1.)
@@ -260,16 +260,15 @@ vec2 mainAudio( vec4 time ) {
260260
);
261261

262262
int progB = ( time.w < SECTION_AAAA - 8.0 * BEAT )
263-
? 6 * ( int( time.w / ( 8.0 * BEAT ) ) % 8 )
263+
? 6 * ( int( time.z / ( 8.0 * BEAT ) ) % 8 )
264264
: 36;
265265

266266
float bassfreq = n2f( 0.0 );
267267

268268
float sidechain = 1.0;
269269

270270
// -- kick ---------------------------------------------------------------------------------------
271-
if ( inRange( time.w, 64.0 * BEAT, SECTION_NEURO - 16.0 * BEAT ) ) {
272-
float ph = linearstep( 64.0 * BEAT, SECTION_PORTER_FUCKING_ROBINSON, time.w );
271+
if ( inRange( time.w, SECTION_BEGIN + 64.0 * BEAT, SECTION_NEURO - 16.0 * BEAT ) ) {
273272
float t = mod( mod( time.z - 1.5 * BEAT, 4.0 * BEAT ), 2.5 * BEAT );
274273
sidechain = smoothstep( 0.0, 0.7 * BEAT, t );
275274
dest += 0.25 * kick( t, 0.2 );
@@ -280,22 +279,22 @@ vec2 mainAudio( vec4 time ) {
280279
}
281280

282281
// -- click --------------------------------------------------------------------------------------
283-
if ( inRange( time.w, 64.0 * BEAT, SECTION_NEURO - 16.0 * BEAT ) ) {
282+
if ( inRange( time.w, SECTION_BEGIN + 64.0 * BEAT, SECTION_NEURO - 16.0 * BEAT ) ) {
284283
float t = mod( time.x, 0.25 * BEAT );
285284
vec2 w = fbm( vec2( time.w ) ) * 2.0 - 1.0;
286285
dest += 0.3 * exp( -500.0 * t ) * mix( 0.3, 1.0, sidechain ) * w;
287286
}
288287

289288
// -- hihat --------------------------------------------------------------------------------------
290289
if (
291-
inRange( time.w, 64.0 * BEAT, SECTION_NEURO )
290+
inRange( time.w, SECTION_BEGIN + 64.0 * BEAT, SECTION_NEURO )
292291
) {
293292
float t = mod( time.x, 0.5 * BEAT );
294293
dest += 0.03 * mix( 0.3, 1.0, sidechain ) * hihat2( 2.0 * t, 50.0 );
295294
}
296295

297296
// -- longclap -----------------------------------------------------------------------------------
298-
if ( inRange( time.w, 67.0 * BEAT, SECTION_NEURO - 17.0 * BEAT ) ) {
297+
if ( inRange( time.w, SECTION_BEGIN + 67.0 * BEAT, SECTION_NEURO - 17.0 * BEAT ) ) {
299298
float t = mod( time.y - 3.0 * BEAT, 4.0 * BEAT );
300299
// float t = mod( time.z - 2.0 * BEAT, 4.0 * BEAT );
301300
dest += 0.1 * longclap( t, time.w );
@@ -306,10 +305,10 @@ vec2 mainAudio( vec4 time ) {
306305
}
307306

308307
// -- pad ----------------------------------------------------------------------------------------
309-
if ( inRange( time.w, 0.0, SECTION_NEURO ) ) {
308+
if ( inRange( time.w, SECTION_BEGIN, SECTION_NEURO ) ) {
310309
vec2 sum = vec2( 0.0 );
311310

312-
float ph = lofi( time.w, 0.5 * BEAT ) / SECTION_NEURO;
311+
float ph = lofi( time.w - SECTION_BEGIN, 0.5 * BEAT ) / SECTION_NEURO;
313312
float tb = lofi( time.z, 0.5 * BEAT );
314313
float t = time.z - tb;
315314
float rev = 0.02 * exp( -8.0 * t );
@@ -323,10 +322,10 @@ vec2 mainAudio( vec4 time ) {
323322
sum += 0.1 * inRangeSmooth( t, 0.0, 0.48 * BEAT, 1E3 ) * wavetable( phase, radius, vec2( 0.3 * float( i ) ) );
324323
}
325324

326-
if ( inRange( time.w, 64.0 * BEAT, SECTION_NEURO ) ) {
325+
if ( inRange( time.w, SECTION_BEGIN + 64.0 * BEAT, SECTION_NEURO ) ) {
327326
for ( int i = 0; i < 7; i ++ ) {
328327
float rate = n2r( float( chordsA[ i ] ) ) * 0.5;
329-
sum += 0.1 * choir( ( time.w - 64.0 * BEAT ) * rate * 0.5 );
328+
sum += 0.1 * choir( time.z * rate * 0.5 );
330329
}
331330
}
332331

0 commit comments

Comments
 (0)