f@5: /* f@5: f@5: Copyright (C) 2016 Queen Mary University of London f@5: Author: Fiore Martin f@5: f@5: This file is part of Collidoscope. f@5: f@5: Collidoscope is free software: you can redistribute it and/or modify f@5: it under the terms of the GNU General Public License as published by f@5: the Free Software Foundation, either version 3 of the License, or f@5: (at your option) any later version. f@5: f@5: This program is distributed in the hope that it will be useful, f@5: but WITHOUT ANY WARRANTY; without even the implied warranty of f@5: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the f@5: GNU General Public License for more details. f@5: f@5: You should have received a copy of the GNU General Public License f@5: along with this program. If not, see . f@5: */ f@5: 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@5: 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@5: float ratio = (audioSample - (-1.0f)) * 0.5f; // 2 = 1 - (-1) f@0: f@5: /* get bottom and add the scaled height */ f@0: return ratio * mSelectionBarHeight; //remove bounds.getY1() bound only needed for size of tier f@5: } 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@7: return mWindowHeight - ( mWindowHeight / ( 2 * NUM_WAVES ) ) + 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@5: int flipY(int y) const f@0: { f@0: if ( mWaveIndex == 0) f@5: return mWindowHeight - y; f@0: else f@3: return y; f@5: } f@0: f@3: /** f@3: * Returns x. not used at he moment. f@3: * f@3: */ f@5: int flipX(int x) const f@0: { f@0: return x; f@5: } 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: };