To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / CollidoscopeApp / include / Chunk.h @ 7:a4a336624f5a
History | View | Annotate | Download (3.3 KB)
| 1 |
/*
|
|---|---|
| 2 |
|
| 3 |
Copyright (C) 2015 Fiore Martin
|
| 4 |
Copyright (C) 2016 Queen Mary University of London
|
| 5 |
Author: Fiore Martin
|
| 6 |
|
| 7 |
This file is part of Collidoscope.
|
| 8 |
|
| 9 |
Collidoscope is free software: you can redistribute it and/or modify
|
| 10 |
it under the terms of the GNU General Public License as published by
|
| 11 |
the Free Software Foundation, either version 3 of the License, or
|
| 12 |
(at your option) any later version.
|
| 13 |
|
| 14 |
This program is distributed in the hope that it will be useful,
|
| 15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 |
GNU General Public License for more details.
|
| 18 |
|
| 19 |
You should have received a copy of the GNU General Public License
|
| 20 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 21 |
|
| 22 |
*/
|
| 23 |
|
| 24 |
|
| 25 |
#pragma once
|
| 26 |
|
| 27 |
#include "cinder/Color.h" |
| 28 |
#include "cinder/gl/Batch.h" |
| 29 |
|
| 30 |
class DrawInfo; |
| 31 |
|
| 32 |
/**
|
| 33 |
*
|
| 34 |
* A chunk of audio in Collidoscope low-fi visual wave.
|
| 35 |
*
|
| 36 |
* The visual wave of Collidoscope is made out of a number of bars that mimics in a low-fi fashion the typical waveform based representation of audio.
|
| 37 |
* A Chunk is one of the bars of the visual wave.
|
| 38 |
*
|
| 39 |
*/
|
| 40 |
|
| 41 |
class Chunk |
| 42 |
{
|
| 43 |
|
| 44 |
public:
|
| 45 |
|
| 46 |
const static float kWidth; |
| 47 |
const static float kHalfWidth; |
| 48 |
|
| 49 |
/**
|
| 50 |
* Constructor, takes as argument the index of this chunk in the wave
|
| 51 |
*/
|
| 52 |
Chunk( size_t index ); |
| 53 |
|
| 54 |
/**
|
| 55 |
* Sets the top value of this chunk. The value is passed in audio coordinates : [-1.0, 1.0]
|
| 56 |
*/
|
| 57 |
void inline setTop(float t) { mAudioTop = t; mAnimate = 0.0f; mResetting = false; /* startes the animation to crate a chunk */ } |
| 58 |
/**
|
| 59 |
* Sets the bottom value of this chunk. The value is passed in audio coordinates : [-1.0, 1.0]
|
| 60 |
*/
|
| 61 |
void inline setBottom(float b) { mAudioBottom = b; mAnimate = 0.0f; mResetting = false; } |
| 62 |
/**
|
| 63 |
* Get the top value of this chunk. The value is returned in audio coordinates : [-1.0, 1.0]
|
| 64 |
*/
|
| 65 |
float inline getTop() const { return mAudioTop; } |
| 66 |
/**
|
| 67 |
* Get the bottom value of this chunk. The value is returned in audio coordinates : [-1.0, 1.0]
|
| 68 |
*/
|
| 69 |
float inline getBottom() const { return mAudioBottom; } |
| 70 |
|
| 71 |
/**
|
| 72 |
* Reset this chunks. When a chunk is reset it starts shrinking until it disappears.
|
| 73 |
*
|
| 74 |
*/
|
| 75 |
void reset(){
|
| 76 |
mResetting = true;
|
| 77 |
} |
| 78 |
|
| 79 |
/**
|
| 80 |
* Called in the graphic loop. It update this chunk.
|
| 81 |
*/
|
| 82 |
void update( const DrawInfo& di ); |
| 83 |
|
| 84 |
/**
|
| 85 |
* Called in the graphic loop. It draws this chunk.
|
| 86 |
*/
|
| 87 |
void draw( const DrawInfo& di, ci::gl::BatchRef &batch ); |
| 88 |
|
| 89 |
/**
|
| 90 |
* Called in the graphic loop. It draws this chunk all the way to the bottom of the screen.
|
| 91 |
* This method is called when the chunk is the first or last in a selection.
|
| 92 |
*/
|
| 93 |
void drawBar( const DrawInfo& di, ci::gl::BatchRef &batch ); |
| 94 |
|
| 95 |
/**
|
| 96 |
* Informs this chunk that it's the first chunk of the selection.
|
| 97 |
*/
|
| 98 |
void setAsSelectionStart(bool start){ |
| 99 |
isSelectionStart = start; |
| 100 |
} |
| 101 |
|
| 102 |
/**
|
| 103 |
* Informs this chunk that it's the last chunk of the selection.
|
| 104 |
*/
|
| 105 |
void setAsSelectionEnd(bool end){ |
| 106 |
isSelectionEnd = end; |
| 107 |
} |
| 108 |
|
| 109 |
private:
|
| 110 |
|
| 111 |
float mAudioTop;
|
| 112 |
float mAudioBottom;
|
| 113 |
|
| 114 |
float mX;
|
| 115 |
|
| 116 |
float mAnimate = 1.0; |
| 117 |
int mIndex;
|
| 118 |
|
| 119 |
bool isSelectionStart = false; |
| 120 |
bool isSelectionEnd = false; |
| 121 |
|
| 122 |
bool mResetting = false; |
| 123 |
|
| 124 |
}; |