To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / CollidoscopeApp / include / Chunk.h @ 4:ab6db404403a

History | View | Annotate | Download (2.5 KB)

1

    
2
#pragma once
3

    
4
#include "cinder/Color.h"
5
#include "cinder/gl/Batch.h"
6

    
7
class DrawInfo;
8

    
9
/**
10
 *
11
 * A chunk of audio in Collidoscope low-fi visual wave. 
12
 *
13
 * 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.
14
 * A Chunk is one of the bars of the visual wave. 
15
 *
16
 */
17

    
18
class Chunk
19
{
20

    
21
public:
22

    
23
    const static float kWidth;
24
    const static float kHalfWidth;
25

    
26
    /**
27
     * Constructor, takes as argument the index of this chunk in the wave
28
     */ 
29
        Chunk( size_t index );
30

    
31
    /**
32
     * Sets the top value of this chunk. The value is passed in audio coordinates : [-1.0, 1.0]
33
     */
34
    void inline setTop(float t) { mAudioTop = t; mAnimate = 0.0f; mResetting = false; /* startes the animation to crate a chunk */ }
35
    /**
36
     * Sets the bottom value of this chunk. The value is passed in audio coordinates : [-1.0, 1.0]
37
     */
38
    void inline setBottom(float b) { mAudioBottom = b; mAnimate = 0.0f; mResetting = false; }
39
    /**
40
     * Get the top value of this chunk. The value is returned in audio coordinates : [-1.0, 1.0]
41
     */
42
    float inline getTop() const { return mAudioTop; }
43
    /**
44
     * Get the bottom value of this chunk. The value is returned in audio coordinates : [-1.0, 1.0]
45
     */
46
    float inline getBottom() const { return mAudioBottom; }
47

    
48
    /**
49
     * Reset this chunks. When a chunk is reset it starts shrinking until it disappears.
50
     *
51
     */ 
52
        void reset(){
53
                mResetting = true;
54
        }
55

    
56
    /**
57
     * Called in the graphic loop. It update this chunk. 
58
     */ 
59
    void update( const DrawInfo& di );
60

    
61
    /**
62
     * Called in the graphic loop. It draws this chunk. 
63
     */ 
64
    void draw( const DrawInfo& di, ci::gl::BatchRef &batch );
65

    
66
    /**
67
     * Called in the graphic loop. It draws this chunk all the way to the bottom of the screen. 
68
     * This method is called when the chunk is the first or last in a selection. 
69
     */ 
70
    void drawBar( const DrawInfo& di, ci::gl::BatchRef &batch );
71

    
72
    /**
73
     * Informs this chunk that it's the first chunk of the selection.
74
     */ 
75
        void setAsSelectionStart(bool start){
76
                isSelectionStart = start;
77
        }
78

    
79
    /**
80
     * Informs this chunk that it's the last chunk of the selection.
81
     */ 
82
        void setAsSelectionEnd(bool end){
83
                isSelectionEnd = end;
84
        }
85

    
86
private:
87

    
88
    float mAudioTop;
89
    float mAudioBottom;
90

    
91
    float mX;
92

    
93
    float mAnimate = 1.0;
94
    int mIndex;
95

    
96
    bool isSelectionStart = false;
97
    bool isSelectionEnd = false;
98

    
99
    bool mResetting = false;
100

    
101
};