-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSequencer.h
1243 lines (973 loc) · 41.4 KB
/
Sequencer.h
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of fijuu2 (a.k.a fijuuu).
* Copyright (C) 2006 Steven Pickles, Julian Oliver
*
* fijuu2 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* fijuu2 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef H_Sequencer
#define H_Sequencer
#include <math.h>
#include "OSCListener.h"
#include "JoystickListener.h"
#include "MeshWarp.h"
#include <math.h>
#define NUM_TRACKS (6)
#define SAMPLERATE (44100)
#define FRAME_SIZE (64)
#define FRAME_DURATION ((double)FRAME_SIZE/SAMPLERATE)
#define MAX_PERIOD (999936/64)
#define MIN_PERIOD (1)
#define SEQ_SIZE 1024
// 10 minutes
#define IDLE_TIMEOUT (1000*60*10)
struct Frame {
bool mSet;
bool mMute;
bool mBoost;
bool mNoise;
Real mYaw;
Real mPitch;
Real mRoll;
Real mX;
Real mY;
Real mVolume;
void set(bool isset, bool mute=false, bool boost=false, bool noise=false,
Real yaw=0.0, Real pitch=0.0, Real roll=0.0,
Real x=0.0, Real y=0.0)
//Real volume=0.0)
{
mSet=isset;
mMute=mute;
mBoost=boost;
mNoise=noise;
mYaw=yaw;
mPitch=pitch;
mRoll=roll;
mX=x;
mY=y;
//mVolume=volume;
}
};
struct Track {
TexturePtr mTex;
HardwarePixelBufferSharedPtr mBuffer;
MaterialPtr mMaterial;
MaterialPtr mSelectedMaterial;
SceneNode *mOffsetNode;
SceneNode *mRotScaleNode;
Real mVolume;
Entity *mEntity;
Timer *mTimer;
bool mPlaying;
Real mPhase;
//Real mRPM;
Real mPeriod; //in frames
Real mLastUpdatePhase;
String mOSCName;
Frame mFrames[SEQ_SIZE];
};
class Sequencer: public FrameListener
{
protected:
// needed for compositors
RenderWindow* mWindow;
MaterialPtr mBaseMaterial;
MaterialPtr mBaseSelectedMaterial;
Entity *mBaseEntity;
Entity *mGuideEntity;
SceneNode *mGuideNode;
SceneManager *mSceneMgr;
Track mTracks[NUM_TRACKS];
Real minVolScale, maxVolScale;
SceneNode *mRotNode;
SceneNode *mWarpNode;
//SceneNode *extraNode;
OSCListener *mOSCListener;
JoystickListener *mJoystickListener;
bool mRecording;
bool mMute;
bool mIdle;
Timer *mIdleTimer;
bool mNoise;
bool mBoost;
int mSelectedTrack;
enum Mode
{
MODE_UNKNOWN,
MODE_TWIST,
MODE_TIMESTRETCH,
MODE_RESAMPLE,
MODE_VOLUME
} mMode;
// special entities for meshwarps
Entity *mDiverHead;
MeshWarpListener *mMeshWarpListener;
SceneNode *mTwistAxes;
Real mStretchBaseRPM;
Real mBaseVolume;
// filters
LowPassFilter mNoiseLPF;
LowPassFilter mBoostLPF;
// compositors
CompositorInstance *mBloom;
CompositorInstance *mOldFarked;
CompositorInstance *mSharpenEdges;
CompositorInstance *mBlackAndWhite;
// overlays
Overlay *mRecordOverlay;
Overlay *mMuteOverlay;
Overlay *mTwistUsageOverlay;
Overlay *mStretchUsageOverlay;
Overlay *mTimeStretchCaptionOverlay;
Overlay *mNoiseOverlay;
Overlay *mVolumeUsageOverlay;
Overlay *mBoostOverlay;
Overlay *mTwistCaptionOverlay;
Overlay *mLogoOverlay;
// for preloading
MeshPtr mHunk;
MeshPtr mDiver;
MeshPtr mMilk;
MeshPtr mManowar;
MeshPtr mPoints;
MeshPtr mTurbulence;
public:
static void sendFrame(Frame &frame, OSCListener *mOSCListener, Track &track)
{
mOSCListener->send(track.mOSCName+"/twistAxis",frame.mYaw,frame.mPitch,frame.mRoll);
mOSCListener->send(track.mOSCName+"/twistAngle",frame.mX,frame.mY);
mOSCListener->send(track.mOSCName+"/mute",frame.mMute?1:0);
mOSCListener->send(track.mOSCName+"/noise",frame.mNoise?1:0);
mOSCListener->send(track.mOSCName+"/boost",frame.mBoost?1:0);
//mOSCListener->send(track.mOSCName+"/volume",frame.mVolume);
}
static float rescale(Real in, Real in_low, Real in_high, Real out_low, Real out_high)
{
Real in_width = in_high-in_low;
Real out_width = out_high-out_low;
return out_low+((in-in_low)*out_width/(in_width));
}
static float symmetricLogScale(Real in, Real out_mul)
{
// the follwing function assumes x is [0,1] ..
// but in is -1,1, so...
Real x = (in+1.0)/2.0;
Real out_min = 1.0/out_mul;
Real out_max = out_mul;
return out_min * exp(log(out_max/out_min)*x);
}
Sequencer(RenderWindow *win, SceneNode *sceneNode, String name, OSCListener *oscListener, JoystickListener *joystickListener)
: mNoiseLPF(3), mBoostLPF(3)
{
mWindow = win;
mOSCListener = oscListener;
mJoystickListener = joystickListener;
mSceneMgr = sceneNode->getCreator();
mBaseEntity = mSceneMgr->createEntity(name+"ring","TorusUV3-5.mesh");
mBaseMaterial = MaterialManager::getSingleton().getByName("fijuuu/dynHead");
mBaseSelectedMaterial = MaterialManager::getSingleton().getByName("fijuuu/dyn3");
mGuideEntity = mSceneMgr->createEntity(name+"guide","Guide.mesh");
mRotNode = sceneNode->createChildSceneNode();
mWarpNode = mRotNode->createChildSceneNode("warpNode");
// preload
mHunk = MeshManager::getSingleton().load("hunk.mesh",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
mDiver = MeshManager::getSingleton().load("diver.mesh",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
mMilk = MeshManager::getSingleton().load("milk.mesh",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
mManowar = MeshManager::getSingleton().load("manowar.mesh",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
mPoints = MeshManager::getSingleton().load("points.mesh",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
mTurbulence = MeshManager::getSingleton().load("turbulence.mesh",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
mMeshWarpListener = new MeshWarpListener(mSceneMgr,mWarpNode);
//mMeshWarpListener->setObject(mHunk->getName());
// everyone else uses the mRoot object.. i hope this is the same thing.
Root::getSingleton().addFrameListener(mMeshWarpListener);
mMode = MODE_UNKNOWN;
mRecording = mMute = 0;
mIdle = 1;
mIdleTimer = PlatformManager::getSingleton().createTimer();
minVolScale = 1;
maxVolScale = 2;
//create the tracks
for(int i=0;i<NUM_TRACKS;i++) {
createTrack(
mTracks[i],
sceneNode,
name+"ring-"+StringConverter::toString(i),
i*3
,"/track/"+StringConverter::toString(i));
}
resetAllTracks();
createScene(sceneNode);
// so that lastSelectedTrack is invalid
mSelectedTrack = -1;
selectTrack(0);
}
~Sequencer()
{
delete mMeshWarpListener;
}
// here we mostly create things (entities, compositors) that get enabled/disabled later
// like, on track changes
void createScene(SceneNode *sceneNode)
{
mDiverHead = mSceneMgr->createEntity("diverHead","diverHead.mesh");
mTwistAxes = mWarpNode->createChildSceneNode();
Entity *axesEnt = mSceneMgr->createEntity("axes","fij_axes.mesh");
// the mTwistAxes node is used by the meshwarp as the variable for storing the current twist,
// so if you want to hide the axes, just comment out this next line to stop the mesh being attached.
mTwistAxes->attachObject(axesEnt);
mTwistAxes->setScale(0.1,0.1,0.1);
axesEnt->setCastShadows(false);
SceneNode *sn;
mGuideNode = mSceneMgr->createSceneNode();
Node *n;
if((n = mGuideNode->getParent())!=0)
{
LogManager::getSingleton().logMessage("guidenode has a parent? "+n->getName());
}
else
{
LogManager::getSingleton().logMessage("guidenode has no parent");
}
sn = mGuideNode->createChildSceneNode();
sn->setInheritScale(false);
sn->setPosition(13,0.59,0);
sn->attachObject(mGuideEntity->clone("guide0"));
sn = mGuideNode->createChildSceneNode();
sn->yaw(Radian(Math::HALF_PI));
sn = sn->createChildSceneNode();
sn->setInheritScale(false);
sn->setPosition(13,0.59,0);
sn->attachObject(mGuideEntity->clone("guide1"));
sn = mGuideNode->createChildSceneNode();
sn->yaw(Radian(Math::PI));
sn = sn->createChildSceneNode();
sn->setInheritScale(false);
sn->setPosition(13,0.59,0);
sn->attachObject(mGuideEntity->clone("guide2"));
sn = mGuideNode->createChildSceneNode();
sn->yaw(Radian(Math::PI+Math::HALF_PI));
sn = sn->createChildSceneNode();
sn->setInheritScale(false);
sn->setPosition(13,0.59,0);
sn->attachObject(mGuideEntity->clone("guide3"));
// compositors
mBloom = CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0), "Bloom");
mOldFarked = CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0), "oldfarked");
mSharpenEdges = CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0), "Sharpen Edges");
mBlackAndWhite= CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0), "B&W");
// overlays
mRecordOverlay = OverlayManager::getSingleton().getByName("fijuuu/recordOverlay");
mMuteOverlay = OverlayManager::getSingleton().getByName("fijuuu/muteOverlay");
mTwistUsageOverlay = OverlayManager::getSingleton().getByName("fijuuu/useOverlay");
mTwistCaptionOverlay = OverlayManager::getSingleton().getByName("fijuuu/twistCaptionOverlay");
mStretchUsageOverlay = OverlayManager::getSingleton().getByName("fijuuu/stretchUsageOverlay");
mTimeStretchCaptionOverlay = OverlayManager::getSingleton().getByName("fijuuu/timeStretchCaptionOverlay");
mNoiseOverlay = OverlayManager::getSingleton().getByName("fijuuu/noiseOverlay");
mVolumeUsageOverlay = OverlayManager::getSingleton().getByName("fijuuu/volumeUsageOverlay");
mBoostOverlay = OverlayManager::getSingleton().getByName("fijuuu/boostOverlay");
mLogoOverlay = OverlayManager::getSingleton().getByName("fijuuu/logoOverlay");
mLogoOverlay->show();
}
void setMode(enum Mode mode) {
if(mMode==mode)
return;
LogManager::getSingleton().logMessage("Switching from mode "+StringConverter::toString(mMode)+" to mode "+StringConverter::toString(mode));
// cleanup
switch(mMode)
{
case MODE_VOLUME:
// turn off volume overlays here
mVolumeUsageOverlay->hide();
break;
case MODE_TWIST:
//mOSCListener->send(mTracks[mSelectedTrack].mOSCName+"/twist",0);
// turn off twist usage overlay here
mTwistUsageOverlay->hide();
mTwistCaptionOverlay->hide();
break;
case MODE_TIMESTRETCH:
//mOSCListener->send(mTracks[mSelectedTrack].mOSCName+"/stretch",0);
// turn off timestrech usage overlay here
mStretchUsageOverlay->hide();
mTimeStretchCaptionOverlay->hide();
break;
}
mMode=mode;
// setup
switch(mMode)
{
case MODE_VOLUME:
mBaseVolume = mTracks[mSelectedTrack].mVolume;
// turn on volume overlays here
mVolumeUsageOverlay->show();
break;
case MODE_TWIST:
//mOSCListener->send(mTracks[mSelectedTrack].mOSCName+"/twist",1);
// turn on twist usage overlay here
mTwistUsageOverlay->show();
mTwistCaptionOverlay->show();
break;
case MODE_TIMESTRETCH:
//mStretchBaseRPM = mTracks[mSelectedTrack].mRPM;
mStretchBaseRPM = getTrackRPM(mTracks[mSelectedTrack]);
//mOSCListener->send(mTracks[mSelectedTrack].mOSCName+"/stretch",1);
// turn on overlay here
mStretchUsageOverlay->show();
mTimeStretchCaptionOverlay->show();
break;
}
}
/*
void setTwistIdle(bool idle)
{
if(mTwistIdle==idle)
retun;
}
*/
bool frameStarted(const FrameEvent &evt)
{
const Real &tslf = evt.timeSinceLastFrame;
Track &track = mTracks[mSelectedTrack];
JoystickListener *jl = mJoystickListener;
Button &stretchButton = jl->getButton(1);
Axis &timeAxis = jl->getAxis(0);
Axis &pitchAxis = jl->getAxis(0);
Button &clearButton = jl->getButton(3);
Button &clearAllButton = jl->getButton(8);
Button &volumeButton = jl->getButton(2);
Axis &volumeAxis = jl->getAxis(1);
Axis &twistAxis0 = jl->getAxis(0);
Axis &twistAxis1 = jl->getAxis(1);
Axis &twistAxis2 = jl->getAxis(2);
Axis &twistAxis3 = jl->getAxis(3);
Frame frames[NUM_TRACKS];
Frame &frame = frames[mSelectedTrack];
// read frames for all tracks
for(int i=0;i<NUM_TRACKS;i++) {
// ugly overloading
Track &track = mTracks[i];
Real phase = getTrackPhaseFromTimer(track);
int index = iclip((int)(phase*SEQ_SIZE),0,SEQ_SIZE);
Frame &frame = track.mFrames[index];
if(frame.mSet)
frames[i]=track.mFrames[index];
else
frames[i].set(false);
}
// send after this processing
switch(mMode)
{
case MODE_VOLUME:
if(!volumeButton.getState())
{
mIdleTimer->reset();
setMode(MODE_TWIST);
}
setTrackVolume(track,
-volumeAxis.getLPFPosition()+mBaseVolume);
break;
case MODE_TIMESTRETCH:
if(!stretchButton.getState())
{
if(timeAxis.isDead()&&pitchAxis.isDead())
{
setMode(MODE_TWIST);
break;
}
else
{
// FIXME: setMode(MODE_RESAMPLE);
setMode(MODE_TWIST);
}
}
setTrackRPM(track,symmetricLogScale(-timeAxis.getPosition(),2.0)*mStretchBaseRPM);
break;
case MODE_TWIST:
if(stretchButton.getState())
{
mIdleTimer->reset();
setMode(MODE_TIMESTRETCH);
break;
}
if(volumeButton.getState())
{
mIdleTimer->reset();
setMode(MODE_VOLUME);
break;
}
// this block is to allow temporary variable definitions without errors
{
bool isMuted = jl->getButton(4).getState();
bool isRecording = jl->getButton(5).getState();
bool boost = jl->getButton(6).getState();
bool noise = jl->getButton(7).getState();
mIdle =
twistAxis0.isDead() &&
twistAxis1.isDead() &&
twistAxis2.isDead() &&
twistAxis3.isDead() &&
// err....
!isMuted && !boost && !noise;
if(!mIdle)
mIdleTimer->reset();
if(clearButton.buttonDown())
clearTrack(track);
// reset if idle for 10 minutes.
if(clearAllButton.buttonDown() || (mIdle && mIdleTimer->getMilliseconds()>IDLE_TIMEOUT))
{
mIdleTimer->reset();
resetAllTracks();
}
//clearAllTracks();
// we still use these external functions to update the frame
setRecording(isRecording);
// when there is a mute overlay, you don't want it coming on when you are in the deadspot.
// so we wil need two params here.. both send a mute message to pd but only one displays
// the overlay
// we still use setMute to show overlays
setMute(isMuted);
//setMute(idle ||
// jl->getButton(4).getState());
if(jl->getAxis(5).getNegativeButton().buttonDown()) selectNextTrack();
if(jl->getAxis(5).getPositiveButton().buttonDown()) selectPreviousTrack();
String trackNum = StringConverter::toString(mSelectedTrack);
mTwistAxes->yaw(Radian(jl->getAxis(0).getLPFPosition()*Math::TWO_PI*0.1*tslf));
mTwistAxes->pitch(Radian(jl->getAxis(3).getLPFPosition()*Math::TWO_PI*0.1*tslf));
//mOSCListener->send(track.mOSCName+"/twistAxis",o.getYaw().valueDegrees(),o.getPitch().valueDegrees(),o.getRoll().valueDegrees());
setBoost(boost);
Real boostRamp = mBoostLPF.write(boost?8:10,tslf);
setNoise(noise);
mMeshWarpListener->setDisplacement(mNoiseLPF.write(noise?0.5:0,tslf));
Axis &xTwistAxis = jl->getAxis(1);
Axis &yTwistAxis = jl->getAxis(2);
//mOSCListener->send(track.mOSCName+"/twistAngle",xTwistAxis.getPosition(),yTwistAxis.getPosition());
if(!mIdle || isRecording) {
frame.mMute = isMuted;
frame.mBoost = boost;
frame.mNoise = noise;
Quaternion o = mTwistAxes->getOrientation();
frame.mYaw = o.getYaw().valueDegrees();
frame.mPitch = o.getPitch().valueDegrees();
frame.mRoll = o.getRoll().valueDegrees();
frame.mX = xTwistAxis.getPosition();
frame.mY = yTwistAxis.getPosition();
}
// there is now the possibility to set these things from the recording..
// well not quite, since we loose the axes, but we could... if...
mMeshWarpListener->setTwist(0,
mTwistAxes->getOrientation().xAxis(),
xTwistAxis.getLPFPosition()*Math::PI/(boostRamp),
0);
mMeshWarpListener->setTwist(1,
mTwistAxes->getOrientation().yAxis(),
yTwistAxis.getLPFPosition()*Math::PI/(boostRamp),
0);
//frame.send(mOSCListener,track);
/*
if(isRecording) {
updateTrackSeq(track,frame);
}
*/
}
break;
default:
LogManager::getSingleton().logMessage("unknown mode...");
setMode(MODE_TWIST);
break;
}
// rotate the meshWarp
mRotNode->yaw(Degree(1)*evt.timeSinceLastFrame);
// update the seq.. should we do this all the time?
update(frame);
for(int i=0;i<NUM_TRACKS;i++) {
Track &track = mTracks[i];
sendFrame(frames[i],mOSCListener,track);
mOSCListener->send(track.mOSCName+"/volume",track.mVolume);
}
return true;
}
void setRecording(bool recording)
{
if(recording==mRecording)
return;
mRecording = recording;
if(mRecording)
{
mRecordOverlay->show();
mBlackAndWhite->setEnabled(true);
}
else
{
mRecordOverlay->hide();
if(!mMute) mBlackAndWhite->setEnabled(false);
}
Track &track = mTracks[mSelectedTrack];
//mOSCListener->send(track.mOSCName+"/recording",mRecording?1.0:0.0,getTrackPhaseFromTimer(track));
}
void setMute(bool mute)
{
/* i'll just put these notes here..
* with the old method, if you were idle, and there was nothing recorded, you would hear nothing
*
* i guess it's the same now if we full the seq full of mutes at startup
*/
if(mute==mMute)
return;
mMute = mute;
if(!mMute) {
// clean up
// remember to turn off here anything you turn on below..
mMuteOverlay->hide();
mBloom->setEnabled(false);
if(!mRecording) mBlackAndWhite->setEnabled(false);
}
else
{
mBloom->setEnabled(true);
mBlackAndWhite->setEnabled(true);
mMuteOverlay->show();
}
//mOSCListener->send(mTracks[mSelectedTrack].mOSCName+"/mute",mMute?1.0:0.0);
}
void setNoise(bool noise)
{
if(noise==mNoise)
return;
mNoise=noise;
//mOSCListener->send(mTracks[mSelectedTrack].mOSCName+"/noise",mNoise?1:0);
if(!mNoise) {
// clean up
// remember to turn off here anything you turn on below..
mOldFarked->setEnabled(false);
// mSharpenEdges->setEnabled(false);
mNoiseOverlay->hide();
}
else
{
mOldFarked->setEnabled(true);
// mSharpenEdges->setEnabled(true);
mNoiseOverlay->show();
}
}
void setBoost(bool boost)
{
if(boost==mBoost)
return;
mBoost=boost;
//mOSCListener->send(mTracks[mSelectedTrack].mOSCName+"/boost",mBoost?1:0);
if(!mBoost) {
// clean up
// remember to turn off here anything you turn on below..
mBoostOverlay->hide();
mSharpenEdges->setEnabled(false);
}
else
{
mSharpenEdges->setEnabled(true);
mBoostOverlay->show();
}
}
void clearTrack(Track &track) {
track.mBuffer->lock(HardwareBuffer::HBL_NORMAL);
const PixelBox &pb = track.mBuffer->getCurrentLock();
uint32 *data = static_cast<uint32*>(pb.data);
for(unsigned int x=0; x<SEQ_SIZE; x++)
{
/*
// temporarily fill with random data to make it visible
if(Math::UnitRandom()>0.5)
PixelUtil::packColour(1.0f,1.0f,1.0f,1.0f,PF_A8R8G8B8,&data[x]);
else
*/
PixelUtil::packColour(0.0f,0.0f,0.0f,0.0f,PF_A8R8G8B8,&data[x]);
track.mFrames[x].set(false);
}
track.mBuffer->unlock();
}
void clearAllTracks()
{
for(int i=0;i<NUM_TRACKS;i++)
clearTrack(mTracks[i]);
}
void resetAllTracks()
{
for(int i=0;i<NUM_TRACKS;i++)
{
Track &track = mTracks[i];
clearTrack(track);
setTrackVolume(track,0.5);
setTrackRPM(track,Math::RangeRandom(5,10));
}
}
int imax(int a, int b)
{
return a>b?a:b;
}
int imin(int a, int b)
{
return a<b?a:b;
}
int iclip(int n, int low, int high)
{
return imin(imax(n, low), high);
}
Real clip(Real f, Real low, Real high)
{
return (f<low?low:(f>high?high:f));
}
void updateTrackTextureAndSeq(Track &track,Frame frame) {
Real currentPhase = getTrackPhaseFromTimer(track);
if(mRecording)
{
//printf("rec or erase\n");
if(track.mLastUpdatePhase<0.0)
{
//printf("unknown last update phase\n");
track.mLastUpdatePhase=currentPhase;
}
int start = iclip((int)(track.mLastUpdatePhase*SEQ_SIZE),0,SEQ_SIZE);
int end = iclip((int)(currentPhase*SEQ_SIZE),0,SEQ_SIZE);
if(start>end)
{
end+=SEQ_SIZE;
}
//printf("start=%d end=%d\n");
track.mBuffer->lock(HardwareBuffer::HBL_NORMAL);
const PixelBox &pb = track.mBuffer->getCurrentLock();
uint32 *data = static_cast<uint32*>(pb.data);
for(unsigned int x=start; x<end; x++)
{
int mx = x%SEQ_SIZE;
if(mRecording)
{
frame.mSet=true;
track.mFrames[mx]=frame;
if(mMute || mIdle)
PixelUtil::packColour(0.0f,0.0f,0.0f,0.0f,PF_A8R8G8B8,&data[mx]);
else
PixelUtil::packColour(1.0f,1.0f,1.0f,1.0f,PF_A8R8G8B8,&data[mx]);
}
}
track.mBuffer->unlock();
track.mLastUpdatePhase=currentPhase;
}
else
{
track.mLastUpdatePhase=-1.0;
}
}
void createTrackSeq(Track &track) {
for(int i=0;i<SEQ_SIZE;i++) {
Frame &frame = track.mFrames[i];
frame.mSet=false;
frame.mMute=true;
frame.mBoost=false;
frame.mNoise=false;
frame.mYaw=0.0;
frame.mPitch=0.0;
frame.mRoll=0.0;
frame.mX=0.0;
frame.mY=0.0;
}
}
void setRecordMaskTexture(MaterialPtr m, String name, TextureType tt)
{
for(Material::TechniqueIterator ti = m->getTechniqueIterator() ;
ti.hasMoreElements() ; ti.moveNext())
for(Technique::PassIterator pi = ti.peekNext()->getPassIterator() ;
pi.hasMoreElements() ; pi.moveNext())
for (Pass::TextureUnitStateIterator tusi = pi.peekNext()->getTextureUnitStateIterator() ;
tusi.hasMoreElements() ; tusi.moveNext())
{
TextureUnitState *tus = tusi.peekNext();
if(StringUtil::startsWith(tus->getName(),"record_mask"))
{
tus->setTextureName(name,tt);
}
}
}
void createTrackMaterial(Track &track, String name) {
// Create dynamic texture
track.mTex = TextureManager::getSingleton().createManual(
name,"General", TEX_TYPE_1D, SEQ_SIZE, 1, 0, PF_A8R8G8B8,
//TU_AUTOMIPMAP);
TU_DYNAMIC_WRITE_ONLY);
track.mBuffer = track.mTex->getBuffer(0, 0);
track.mMaterial = mBaseMaterial->clone(name);
setRecordMaskTexture(track.mMaterial,name,TEX_TYPE_1D);
track.mSelectedMaterial = mBaseSelectedMaterial->clone(name+"-selected");
setRecordMaskTexture(track.mSelectedMaterial,name,TEX_TYPE_1D);
clearTrack(track);
}
/*
Real wrap(Real f) {
return f-((int)f);
}
*/
Real getTrackPhaseFromTimer(Track &track) {
Real junk;
if(track.mPlaying)
{
//return modff(track.mPhase + (track.mTimer->getMicroseconds()*track.mRPM/60000000.0),&junk);
return modff(track.mPhase + (track.mTimer->getMicroseconds()/(track.mPeriod*FRAME_DURATION*1000000.0)),&junk);
}
else
{
return track.mPhase;
}
}
// use timer to update track phase
void updateTrackPhase(Track &track) {
Real phase = getTrackPhaseFromTimer(track);
// FIXME: unnecessary now
// mOSCListener->send(track.mOSCName+"/period",track.mPeriod,phase);
applyTrackPhase(track,phase);
}
void setTrackPeriod(Track &track, int period)
{
//printf("set track period %d\n",period);
Real currentPhase = getTrackPhaseFromTimer(track);
track.mTimer->reset();
track.mPeriod = iclip(period,MIN_PERIOD,MAX_PERIOD);
track.mPhase = currentPhase;
// mOSCListener->send(track.mOSCName+"/period",track.mPeriod,track.mPhase);
}
Real getTrackRPM(Track &track)
{
Real rpm = (60.0/(track.mPeriod*FRAME_DURATION));
//printf("gettrackrpm==%f\n",rpm);
return rpm;
}
void setTrackRPM(Track &track, Real RPM)
{
//printf("set track rpm %f, frame duration %f\n",RPM,FRAME_DURATION);
setTrackPeriod(track,(int)(round(60.0/(RPM*FRAME_DURATION))));
}
void startTrack(Track &track)
{
if(!track.mPlaying)
{
track.mTimer->reset();
track.mPlaying=true;
}
}
void stopTrack(Track &track)
{
Real currentPhase = getTrackPhaseFromTimer(track);
track.mTimer->reset();
track.mPhase = currentPhase;
track.mPlaying=false;