annotate CollidoscopeApp/include/Oscilloscope.h @ 0:02467299402e

First import CollidoscopeApp for Raspberry Pi JackDevice Teensy code for Collidoscope
author Fiore Martin <f.martin@qmul.ac.uk>
date Thu, 30 Jun 2016 14:50:06 +0200
parents
children dd889fff8423
rev   line source
f@0 1 #pragma once
f@0 2
f@0 3 #include "cinder/gl/gl.h"
f@0 4
f@0 5 #include "DrawInfo.h"
f@0 6
f@0 7 class Oscilloscope
f@0 8 {
f@0 9
f@0 10 public:
f@0 11
f@0 12 Oscilloscope( size_t numPoints ):
f@0 13 mNumPoints( numPoints ),
f@0 14 mLine( std::vector<ci::vec2>( numPoints, ci::vec2() ) )
f@0 15 {}
f@0 16
f@0 17 void setPoint( int index, float audioVal, const DrawInfo &di ){
f@0 18
f@0 19 if ( audioVal > 1.0f ){
f@0 20 audioVal = 1.0f;
f@0 21 }
f@0 22 else if ( audioVal < -1.0f ){
f@0 23 audioVal = -1.0f;
f@0 24 }
f@0 25
f@0 26 audioVal *= 0.8f;
f@0 27 // this yRatio is for the bottom scope, the top will be drawn with a translation/4
f@0 28 // because it's half of the half of the tier where the wave is drawn
f@0 29 float yRatio = ((1 + audioVal) / 2.0f) * (di.getWindowHeight() / NUM_WAVES );
f@0 30 float xRatio = index * (di.getWindowWidth() / (float)mLine.size());
f@0 31
f@0 32 mLine.getPoints()[index].x = float( di.flipX( int(xRatio) ) );
f@0 33 mLine.getPoints()[index].y = float( di.flipY( int(yRatio) ) );
f@0 34
f@0 35 // add the missing line to reach the right of the window
f@0 36 // indeed the scope starts from 0 to size -1 and adds xRatio
f@0 37 // to each new point to the line from n-1 to n is missing
f@0 38 if (index == mNumPoints - 1){
f@0 39 xRatio += ( di.getWindowWidth() / mNumPoints );
f@0 40 xRatio = ceil( xRatio ); // ceil because the division might left one pixel out
f@0 41
f@0 42 mLine.getPoints()[mNumPoints - 1].x = di.flipX( xRatio );
f@0 43 mLine.getPoints()[mNumPoints - 1].y = di.flipY( yRatio );
f@0 44 }
f@0 45
f@0 46 }
f@0 47
f@0 48 void draw()
f@0 49 {
f@0 50 ci::gl::color(1.0f, 1.0f, 1.0f);
f@0 51 ci::gl::draw( mLine );
f@0 52 }
f@0 53
f@0 54 size_t getNumPoints() const
f@0 55 {
f@0 56 return mNumPoints;
f@0 57 }
f@0 58
f@0 59 private:
f@0 60 size_t mNumPoints;
f@0 61 ci::PolyLine2f mLine;
f@0 62
f@0 63 };