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 / DrawInfo.h

History | View | Annotate | Download (4.01 KB)

1
/*
2

3
 Copyright (C) 2016  Queen Mary University of London 
4
 Author: Fiore Martin
5

6
 This file is part of Collidoscope.
7
 
8
 Collidoscope is free software: you can redistribute it and/or modify
9
 it under the terms of the GNU General Public License as published by
10
 the Free Software Foundation, either version 3 of the License, or
11
 (at your option) any later version.
12

13
 This program is distributed in the hope that it will be useful,
14
 but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 GNU General Public License for more details.
17

18
 You should have received a copy of the GNU General Public License
19
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
*/
21

    
22
#pragma once
23

    
24
#include "cinder/Area.h"
25

    
26
/**
27
 * The DrawInfo class holds size information for drawing the waves in the screen. 
28
 * Every time the screen is resized the draw info is updated with the new information about the window size.
29
 *
30
 * Every wave has its own drawInfo.
31
 *
32
 */ 
33
class DrawInfo
34
{
35
public:
36

    
37
    /**
38
     * Constructor. Takes the index of the wave as argument.
39
     */ 
40
    DrawInfo( size_t waveIndex ):
41
        mWaveIndex( waveIndex ),
42
        mWindowWidth(0),
43
        mWindowHeight(0),
44
        mSelectionBarHeight(0),
45
        mShrinkFactor(1)
46
    {}
47

    
48
    /**
49
     * Reset this DrawInfo using the new bounding area for the wave.  \a shrinkFactor 
50
     * 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.
51
     */ 
52
    void reset( const ci::Area &bounds, float shrinkFactor )
53
    {
54
        mWindowWidth = bounds.getWidth();
55
        mWindowHeight = bounds.getHeight();
56
        mSelectionBarHeight = mWindowHeight / NUM_WAVES;
57
        mShrinkFactor = shrinkFactor;
58
    }
59

    
60
    /**
61
     * Maps a value in the audio space [-1.0, 1.0] to a position on the y axis of this DrawInfo's bounding area.
62
     *
63
     */ 
64
    float audioToHeigt(float audioSample) const {
65
        /* clip into range [-1.1] */
66
        if (audioSample < -1.0f) {
67
            audioSample = -1.0f;
68
        }
69
        else if ( audioSample > 1.0f ){
70
            audioSample = 1.0f;
71
        }
72

    
73
        /* map from [-1,1] to [0,1] */
74
        float ratio = (audioSample - (-1.0f)) * 0.5f; // 2 = 1 - (-1) 
75

    
76
        /* get bottom and add the scaled height */
77
        return ratio * mSelectionBarHeight; //remove  bounds.getY1() bound only needed for size of tier
78
    }
79

    
80
    float getMaxChunkHeight() const 
81
    {
82
        return mSelectionBarHeight * mShrinkFactor;
83
    }
84

    
85
    float getSelectionBarHeight() const
86
    {
87
        return mSelectionBarHeight;
88
    }
89

    
90
    /**
91
     * Returns the center position on the y axis of this DrawInfo's the bounding area. 
92
     */ 
93
    int32_t getWaveCenterY() const
94
    {
95
        if ( mWaveIndex == 0 )
96
            return mWindowHeight - ( mWindowHeight / ( 2 * NUM_WAVES ) ) + 1;
97
        else
98
            return mWindowHeight / (NUM_WAVES * 2);
99
    }
100

    
101
    /**
102
     * Flips y according to the index of the wave. It is needed because the second wave in collidoscope is drawn upside down in the screen.
103
     */ 
104
    int flipY(int y) const 
105
    {
106
        if ( mWaveIndex == 0)
107
            return mWindowHeight - y;
108
        else
109
            return y;
110
    }
111

    
112
    /**
113
     * Returns x. not used at the moment.
114
     *
115
     */ 
116
    int flipX(int x) const
117
    {
118
        return x;
119
    }
120

    
121

    
122
    // how much the wave is shrunk on the y axis with respect to the wave's tier 
123
    float getShrinkFactor() const 
124
    {
125
        return mShrinkFactor;
126
    }
127

    
128
    int32_t getWindowWidth() const
129
    {
130
        return mWindowWidth;
131
    }
132

    
133
    int32_t getWindowHeight() const
134
    {
135
        return mWindowHeight;
136
    }
137

    
138
    /**
139
     * Draw infos cannot be copied and should be passed as const reference.
140
     */ 
141
    DrawInfo( const DrawInfo &original ) = delete;
142
    DrawInfo & operator=( const DrawInfo &original ) = delete;
143

    
144
private:
145
    const size_t mWaveIndex;
146

    
147
    int32_t mWindowHeight;
148
    int32_t mWindowWidth;
149
    int32_t mSelectionBarHeight;
150

    
151
    float mShrinkFactor;
152

    
153
};