f@5: /* f@5: f@5: Copyright (C) 2015 Fiore Martin 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@5: f@0: f@0: #pragma once f@0: f@0: #include "cinder/Color.h" f@0: #include "cinder/gl/Batch.h" f@0: f@0: class DrawInfo; f@0: f@2: /** f@2: * f@2: * A chunk of audio in Collidoscope low-fi visual wave. f@2: * f@16: * The visual wave of Collidoscope is made out of a number of bars that mimic, in a low-fi fashion, the typical waveform-based representation of audio. f@2: * A Chunk is one of the bars of the visual wave. f@2: * f@2: */ f@2: f@0: class Chunk f@0: { f@0: f@0: public: f@0: f@0: const static float kWidth; f@0: const static float kHalfWidth; f@0: f@2: /** f@16: * Constructor, takes as argument the index of this chunk in the wave that contains it f@2: */ f@5: Chunk( size_t index ); f@0: f@2: /** f@2: * Sets the top value of this chunk. The value is passed in audio coordinates : [-1.0, 1.0] f@2: */ f@0: void inline setTop(float t) { mAudioTop = t; mAnimate = 0.0f; mResetting = false; /* startes the animation to crate a chunk */ } f@2: /** f@2: * Sets the bottom value of this chunk. The value is passed in audio coordinates : [-1.0, 1.0] f@2: */ f@0: void inline setBottom(float b) { mAudioBottom = b; mAnimate = 0.0f; mResetting = false; } f@2: /** f@2: * Get the top value of this chunk. The value is returned in audio coordinates : [-1.0, 1.0] f@2: */ f@0: float inline getTop() const { return mAudioTop; } f@2: /** f@2: * Get the bottom value of this chunk. The value is returned in audio coordinates : [-1.0, 1.0] f@2: */ f@0: float inline getBottom() const { return mAudioBottom; } f@0: f@2: /** f@16: * Reset this chunks. When a chunk is reset, it starts shrinking until it disappears or setTop/setBottom are called again f@2: * f@2: */ f@5: void reset(){ f@5: mResetting = true; f@5: } f@0: f@2: /** f@2: * Called in the graphic loop. It update this chunk. f@2: */ f@0: void update( const DrawInfo& di ); f@0: f@2: /** f@2: * Called in the graphic loop. It draws this chunk. f@2: */ f@0: void draw( const DrawInfo& di, ci::gl::BatchRef &batch ); f@0: f@2: /** f@2: * Called in the graphic loop. It draws this chunk all the way to the bottom of the screen. f@2: * This method is called when the chunk is the first or last in a selection. f@2: */ f@0: void drawBar( const DrawInfo& di, ci::gl::BatchRef &batch ); f@0: f@2: /** f@2: * Informs this chunk that it's the first chunk of the selection. f@2: */ f@5: void setAsSelectionStart(bool start){ f@5: isSelectionStart = start; f@5: } f@0: f@2: /** f@2: * Informs this chunk that it's the last chunk of the selection. f@2: */ f@5: void setAsSelectionEnd(bool end){ f@5: isSelectionEnd = end; f@5: } f@0: f@0: private: f@0: f@0: float mAudioTop; f@0: float mAudioBottom; f@0: f@0: float mX; f@0: f@0: float mAnimate = 1.0; f@0: int mIndex; f@0: f@0: bool isSelectionStart = false; f@0: bool isSelectionEnd = false; f@0: f@0: bool mResetting = false; f@0: f@0: };