f@0: #pragma once f@0: f@0: #include "cinder/Area.h" f@0: f@3: /** f@3: * The DrawInfo class holds size information for drawing the waves in the screen. f@3: * Every time the screen is resized the draw info is updated with the new information about the window size. f@3: * f@3: * Every wave has its own drawInfo. f@3: * f@3: */ f@0: class DrawInfo f@0: { f@0: public: f@0: f@3: /** f@3: * Constructor. Takes the index of the wave as argument. f@3: */ f@0: DrawInfo( size_t waveIndex ): f@0: mWaveIndex( waveIndex ), f@0: mWindowWidth(0), f@0: mWindowHeight(0), f@0: mSelectionBarHeight(0), f@0: mShrinkFactor(1) f@0: {} f@0: f@3: /** f@3: * Reset this DrawInfo using the new bounding area for the wave. \a shrinkFactor f@3: * makes the wave shrink on the y axis with respect to the area. A factor 1 makes the wave as big as the area, whereas a factor >1 makes it shrink. f@3: */ f@0: void reset( const ci::Area &bounds, float shrinkFactor ) f@0: { f@0: mWindowWidth = bounds.getWidth(); f@0: mWindowHeight = bounds.getHeight(); f@0: mSelectionBarHeight = mWindowHeight / NUM_WAVES; f@0: mShrinkFactor = shrinkFactor; f@0: } f@0: f@3: /** f@3: * Maps a value in the audio space [-1.0, 1.0] to a position on the y axis of this DrawInf's bounding area. f@3: * f@3: */ f@0: float audioToHeigt(float audioSample) const { f@0: /* clip into range [-1.1] */ f@0: if (audioSample < -1.0f) { f@0: audioSample = -1.0f; f@0: } f@0: else if ( audioSample > 1.0f ){ f@0: audioSample = 1.0f; f@0: } f@0: f@0: /* map from [-1,1] to [0,1] */ f@0: float ratio = (audioSample - (-1.0f)) * 0.5f; // 2 = 1 - (-1) f@0: f@0: /* get bottom and add the scaled height */ f@0: return ratio * mSelectionBarHeight; //remove bounds.getY1() bound only needed for size of tier f@0: } f@0: f@0: float getMaxChunkHeight() const f@0: { f@0: return mSelectionBarHeight * mShrinkFactor; f@0: } f@0: f@0: float getSelectionBarHeight() const f@0: { f@0: return mSelectionBarHeight; f@0: } f@0: f@3: /** f@3: * Returns the center position on the y axis of this DrawInfo's the bounding area. f@3: */ f@0: int32_t getWaveCenterY() const f@0: { f@0: if ( mWaveIndex == 0 ) f@0: return mWindowHeight * 0.75f + 1; f@0: else f@0: return mWindowHeight / (NUM_WAVES * 2); f@0: } f@0: f@3: /** f@3: * Flips y according to the index of the wave. It is needed because the second wave in collidoscope is upside down from the orientation oftthe screen. f@3: */ f@0: int flipY(int y) const f@0: { f@0: if ( mWaveIndex == 0) f@3: return mWindowHeight - y; f@0: else f@3: return y; f@0: } f@0: f@3: /** f@3: * Returns x. not used at he moment. f@3: * f@3: */ f@0: int flipX(int x) const f@0: { f@0: return x; f@0: } f@0: f@0: f@0: // how much the wave is shrunk on the y axis with respect to the wave's tier f@0: float getShrinkFactor() const f@0: { f@0: return mShrinkFactor; f@0: } f@0: f@0: int32_t getWindowWidth() const f@0: { f@0: return mWindowWidth; f@0: } f@0: f@0: int32_t getWindowHeight() const f@0: { f@0: return mWindowHeight; f@0: } f@0: f@3: /** f@3: * Draw infos cannot be copied and should be passed as const reference. f@3: */ f@0: DrawInfo( const DrawInfo &original ) = delete; f@0: DrawInfo & operator=( const DrawInfo &original ) = delete; f@0: f@0: private: f@0: const size_t mWaveIndex; f@0: f@0: int32_t mWindowHeight; f@0: int32_t mWindowWidth; f@0: int32_t mSelectionBarHeight; f@0: f@0: float mShrinkFactor; f@0: f@0: };