annotate CollidoscopeApp/include/DrawInfo.h @ 0:02467299402e

First import CollidoscopeApp for Raspberry Pi JackDevice Teensy code for Collidoscope
author Fiore Martin <f.martin@qmul.ac.uk>
date Thu, 30 Jun 2016 14:50:06 +0200
parents
children 7fb593d53361
rev   line source
f@0 1 #pragma once
f@0 2
f@0 3 #include "cinder/Area.h"
f@0 4
f@0 5 class DrawInfo
f@0 6 {
f@0 7 public:
f@0 8
f@0 9 DrawInfo( size_t waveIndex ):
f@0 10 mWaveIndex( waveIndex ),
f@0 11 mWindowWidth(0),
f@0 12 mWindowHeight(0),
f@0 13 mSelectionBarHeight(0),
f@0 14 mShrinkFactor(1)
f@0 15 {}
f@0 16
f@0 17 void reset( const ci::Area &bounds, float shrinkFactor )
f@0 18 {
f@0 19 mWindowWidth = bounds.getWidth();
f@0 20 mWindowHeight = bounds.getHeight();
f@0 21 mSelectionBarHeight = mWindowHeight / NUM_WAVES;
f@0 22 mShrinkFactor = shrinkFactor;
f@0 23 }
f@0 24
f@0 25 float audioToHeigt(float audioSample) const {
f@0 26 /* clip into range [-1.1] */
f@0 27 if (audioSample < -1.0f) {
f@0 28 audioSample = -1.0f;
f@0 29 }
f@0 30 else if ( audioSample > 1.0f ){
f@0 31 audioSample = 1.0f;
f@0 32 }
f@0 33
f@0 34 /* map from [-1,1] to [0,1] */
f@0 35 float ratio = (audioSample - (-1.0f)) * 0.5f; // 2 = 1 - (-1)
f@0 36
f@0 37 /* get bottom and add the scaled height */
f@0 38 return ratio * mSelectionBarHeight; //remove bounds.getY1() bound only needed for size of tier
f@0 39 }
f@0 40
f@0 41 float getMaxChunkHeight() const
f@0 42 {
f@0 43 return mSelectionBarHeight * mShrinkFactor;
f@0 44 }
f@0 45
f@0 46 float getSelectionBarHeight() const
f@0 47 {
f@0 48 return mSelectionBarHeight;
f@0 49 }
f@0 50
f@0 51 int32_t getWaveCenterY() const
f@0 52 {
f@0 53 if ( mWaveIndex == 0 )
f@0 54 return mWindowHeight * 0.75f + 1;
f@0 55 else
f@0 56 return mWindowHeight / (NUM_WAVES * 2);
f@0 57 }
f@0 58
f@0 59 int flipY(int y) const
f@0 60 {
f@0 61 if ( mWaveIndex == 0)
f@0 62 return mWindowHeight - y /*+ 24*/;
f@0 63 else
f@0 64 return y /*- 24*/;
f@0 65 }
f@0 66
f@0 67 int flipX(int x) const
f@0 68 {
f@0 69 return x;
f@0 70 }
f@0 71
f@0 72
f@0 73 // how much the wave is shrunk on the y axis with respect to the wave's tier
f@0 74 float getShrinkFactor() const
f@0 75 {
f@0 76 return mShrinkFactor;
f@0 77 }
f@0 78
f@0 79 int32_t getWindowWidth() const
f@0 80 {
f@0 81 return mWindowWidth;
f@0 82 }
f@0 83
f@0 84 int32_t getWindowHeight() const
f@0 85 {
f@0 86 return mWindowHeight;
f@0 87 }
f@0 88
f@0 89 DrawInfo( const DrawInfo &original ) = delete;
f@0 90 DrawInfo & operator=( const DrawInfo &original ) = delete;
f@0 91
f@0 92 private:
f@0 93 const size_t mWaveIndex;
f@0 94
f@0 95 int32_t mWindowHeight;
f@0 96 int32_t mWindowWidth;
f@0 97 int32_t mSelectionBarHeight;
f@0 98
f@0 99 float mShrinkFactor;
f@0 100
f@0 101 };