# HG changeset patch # User Robert Tubb # Date 1365524071 -3600 # Node ID 8ed7522deaaa408d380ddded84706eccb9026fae # Parent a42903c61558a5458813bc2a8ee2333751c85908 Interpolation. diff -r a42903c61558 -r 8ed7522deaaa QuestionnaireViewController.xib --- a/QuestionnaireViewController.xib Tue Apr 09 13:22:28 2013 +0100 +++ b/QuestionnaireViewController.xib Tue Apr 09 17:14:31 2013 +0100 @@ -1,7 +1,7 @@ - 1552 + 1280 11G63 3084 1138.51 @@ -1102,6 +1102,10 @@ 0 IBIPadFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + YES 3 2083 diff -r a42903c61558 -r 8ed7522deaaa SliderViewController.h --- a/SliderViewController.h Tue Apr 09 13:22:28 2013 +0100 +++ b/SliderViewController.h Tue Apr 09 17:14:31 2013 +0100 @@ -12,4 +12,8 @@ @property (nonatomic, assign) id theOFAppRef; -(IBAction)hide:(id)sender; -(IBAction)show:(id)sender; +- (void)setAppRef:(id)theOFApp; +@property (retain, nonatomic) IBOutlet UISlider *slider1; + + @end diff -r a42903c61558 -r 8ed7522deaaa SliderViewController.mm --- a/SliderViewController.mm Tue Apr 09 13:22:28 2013 +0100 +++ b/SliderViewController.mm Tue Apr 09 17:14:31 2013 +0100 @@ -45,4 +45,12 @@ self.theOFAppRef = sender; self.view.hidden = NO; } +- (void)dealloc { + [_slider1 release]; + [super dealloc]; +} +- (void)viewDidUnload { + [self setSlider1:nil]; + [super viewDidUnload]; +} @end diff -r a42903c61558 -r 8ed7522deaaa SliderViewController.xib --- a/SliderViewController.xib Tue Apr 09 13:22:28 2013 +0100 +++ b/SliderViewController.xib Tue Apr 09 17:14:31 2013 +0100 @@ -1,14 +1,14 @@ - 1536 + 1280 11G63 - 2844 + 3084 1138.51 569.00 com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 1930 + 2083 IBProxyObject @@ -42,7 +42,7 @@ {{35, 52}, {81, 21}} - + _NS:9 NO YES @@ -50,10 +50,9 @@ NO IBIPadFramework Transpose - + 1 - MCAwIDAAA - darkTextColor + MSAxIDEAA 0 @@ -74,7 +73,7 @@ {{35, 111}, {62, 21}} - + _NS:9 NO YES @@ -82,7 +81,7 @@ NO IBIPadFramework 1/4 note - + 0 @@ -95,7 +94,7 @@ {{35, 171}, {62, 21}} - + _NS:9 NO YES @@ -103,7 +102,7 @@ NO IBIPadFramework 1/6 note - + 0 @@ -116,7 +115,7 @@ {{35, 228}, {62, 21}} - + _NS:9 NO YES @@ -124,7 +123,7 @@ NO IBIPadFramework 1/7 note - + 0 @@ -137,7 +136,7 @@ {{35, 288}, {62, 21}} - + _NS:9 NO YES @@ -145,7 +144,7 @@ NO IBIPadFramework 1/8 note - + 0 @@ -158,7 +157,7 @@ {{56, 16}, {188, 21}} - + _NS:9 NO YES @@ -166,7 +165,7 @@ NO IBIPadFramework Note Pattern Oscillations - + 0 @@ -179,7 +178,7 @@ {{470, 19}, {166, 21}} - + _NS:9 NO YES @@ -187,7 +186,7 @@ NO IBIPadFramework Synth Sound Controls - + 0 @@ -200,7 +199,7 @@ {{421, 82}, {308, 23}} - + _NS:9 NO IBIPadFramework @@ -217,7 +216,7 @@ {{423, 52}, {78, 21}} - + _NS:9 NO YES @@ -225,7 +224,7 @@ NO IBIPadFramework Waveform - + 0 @@ -238,7 +237,7 @@ {{421, 142}, {308, 23}} - + _NS:9 NO IBIPadFramework @@ -252,7 +251,7 @@ {{423, 111}, {82, 21}} - + _NS:9 NO YES @@ -260,7 +259,7 @@ NO IBIPadFramework FIlter Type - + 0 @@ -273,7 +272,7 @@ {{421, 199}, {308, 23}} - + _NS:9 NO IBIPadFramework @@ -287,7 +286,7 @@ {{423, 171}, {123, 21}} - + _NS:9 NO YES @@ -295,7 +294,7 @@ NO IBIPadFramework Filter Frequency - + 0 @@ -308,7 +307,7 @@ {{421, 259}, {308, 23}} - + _NS:9 NO IBIPadFramework @@ -322,7 +321,7 @@ {{423, 230}, {71, 21}} - + _NS:9 NO YES @@ -330,7 +329,7 @@ NO IBIPadFramework Envelope - + 0 @@ -343,6 +342,7 @@ {{421, 321}, {308, 23}} + _NS:9 NO IBIPadFramework @@ -356,7 +356,7 @@ {{423, 288}, {86, 21}} - + _NS:9 NO YES @@ -364,7 +364,7 @@ NO IBIPadFramework FM amount - + 0 @@ -377,6 +377,7 @@ {{33, 82}, {308, 23}} + _NS:9 NO IBIPadFramework @@ -393,6 +394,7 @@ {{33, 142}, {308, 23}} + _NS:9 NO IBIPadFramework @@ -406,6 +408,7 @@ {{33, 199}, {308, 23}} + _NS:9 NO IBIPadFramework @@ -419,6 +422,7 @@ {{33, 259}, {308, 23}} + _NS:9 NO IBIPadFramework @@ -432,6 +436,7 @@ {{33, 321}, {308, 23}} + _NS:9 NO IBIPadFramework @@ -449,9 +454,10 @@ 1 - MC40ODg0NzIzMTY2IDAuNDg4NDcyMzE2NiAwLjQ4ODQ3MjMxNjYAA + MCAwIDAAA NO + YES IBUISimulatedFreeformSizeMetricsSentinel Freeform @@ -469,6 +475,14 @@ 3 + + + slider1 + + + + 287 + @@ -506,15 +520,15 @@ - - + + @@ -669,7 +683,7 @@ - 286 + 287 @@ -690,6 +704,17 @@ id + + slider1 + UISlider + + + slider1 + + slider1 + UISlider + + IBProjectSource ./Classes/SliderViewController.h @@ -699,8 +724,12 @@ 0 IBIPadFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + YES 3 - 1930 + 2083 diff -r a42903c61558 -r 8ed7522deaaa TopButtonViewController.mm --- a/TopButtonViewController.mm Tue Apr 09 13:22:28 2013 +0100 +++ b/TopButtonViewController.mm Tue Apr 09 17:14:31 2013 +0100 @@ -87,12 +87,12 @@ - (IBAction)lockSequencePressed:(id)sender { UIBarButtonItem *button = (UIBarButtonItem *)sender; - if([button.title isEqualToString:@"Lock Sequence (X)"]){ + if([button.title isEqualToString:@"Lock X"]){ ((testApp *)self.theOFAppRef)->lockSequencerPressed(true); - button.title = @"Unlock Sequence (X)"; - }else if([button.title isEqualToString:@"Unlock Sequence (X)"]){ + button.title = @"Unlock X"; + }else if([button.title isEqualToString:@"Unlock X"]){ ((testApp *)self.theOFAppRef)->lockSequencerPressed(false); - button.title = @"Lock Sequence (X)"; + button.title = @"Lock X"; }else{ NSLog(@"button title error"); } @@ -100,12 +100,12 @@ - (IBAction)lockSynthPressed:(id)sender { UIBarButtonItem *button = (UIBarButtonItem *)sender; - if([button.title isEqualToString:@"Lock Synth (Y)"]){ + if([button.title isEqualToString:@"Lock Y"]){ ((testApp *)self.theOFAppRef)->lockSynthPressed(true); - button.title = @"Unlock Synth (Y)"; - }else if([button.title isEqualToString:@"Unlock Synth (Y)"]){ + button.title = @"Unlock Y"; + }else if([button.title isEqualToString:@"Unlock Y"]){ ((testApp *)self.theOFAppRef)->lockSynthPressed(false); - button.title = @"Lock Synth (Y)"; + button.title = @"Lock Y"; }else{ NSLog(@"button title error"); } diff -r a42903c61558 -r 8ed7522deaaa TopButtonViewController.xib --- a/TopButtonViewController.xib Tue Apr 09 13:22:28 2013 +0100 +++ b/TopButtonViewController.xib Tue Apr 09 17:14:31 2013 +0100 @@ -42,6 +42,7 @@ {768, 44} + _NS:9 NO NO @@ -99,13 +100,13 @@ - Lock Sequence (X) + Lock X IBIPadFramework 1 - Lock Synth (Y) + Lock Y IBIPadFramework 1 @@ -400,7 +401,7 @@ - 42 + 43 diff -r a42903c61558 -r 8ed7522deaaa grid.h --- a/grid.h Tue Apr 09 13:22:28 2013 +0100 +++ b/grid.h Tue Apr 09 17:14:31 2013 +0100 @@ -15,9 +15,12 @@ #include "eventLogger.h" #include "presetManager.h" #include "hilbert.h" + using namespace std; class Preset; + + class Grid { public: @@ -30,22 +33,24 @@ void move(TwoVector moveP); // shift view by pixels void zoom(float factor); - + typedef enum{NO_INTERPOLATION, INTERPOLATE_GRID, INTERPOLATE_PRESET} interpolateModeType; + interpolateModeType interpolateMode; void snapCheck(); void shiftCentreToSnapped(); - void draw(); // draw lines - + void draw(); + void drawGridLines(); void update(); // change according to zoom - + int interpLevel; + int smallestGridSpacing; // number of pixels when small grid dissappears from view vector getParams(); TwoVector getCoord(); void setMinZoom(); void setMaxZoom(); // HILBERT now does each coord for this - vector calculateParamsFromCoord(TwoVector coord) const; - TwoVector calculateCoordFromParams(vector params) const; - + vector calculateParamsFromCoord(TwoVector coord); + TwoVector calculateCoordFromParams(vector params); + vector calculateInterpolatedParamsFromCoord(TwoVector coord); TwoVector coordToPixel(TwoVector coord); // the inverse stuff @@ -110,8 +115,8 @@ void setCoord(TwoVector coord); void drawCrossHairs(); - - + int calculateInterpolateLevel(); + vector interpVector(vector upper, vector lower, float frac); diff -r a42903c61558 -r 8ed7522deaaa grid.mm --- a/grid.mm Tue Apr 09 13:22:28 2013 +0100 +++ b/grid.mm Tue Apr 09 17:14:31 2013 +0100 @@ -4,7 +4,7 @@ // // Created by Robert Tubb on 03/10/2012. // -// +// This is the grid view, i.e. the viewable representation of hilbert surface #include "grid.h" @@ -17,6 +17,7 @@ //-------------------------------------------------------------- Grid::Grid(): maxValue(pow(32.0,7.0)-1), minValue(30), paramsPerDim(5), paramBitDepth(7){ + interpLevel = 4; } //-------------------------------------------------------------- //-------------------------------------------------------------- @@ -25,6 +26,8 @@ } void Grid::init(){ + interpolateMode = INTERPOLATE_GRID; + maxZoom = false; minZoom = false; @@ -33,6 +36,8 @@ //set scale and position to random scale = 15500.0; + smallestGridSpacing = 3; //pixels + snapDist = TwoVector(9,9); snapped = false; @@ -54,20 +59,67 @@ setCoord(coord); viewWasChanged(); - + calculateInterpolateLevel(); } template int sgn(T val) { return (T(0) < val) - (val < T(0)); } +//-------------------------------------------------------------- +int Grid::calculateInterpolateLevel(){ + if(interpolateMode == INTERPOLATE_GRID){ + // calculate according to smallest gridlines + // exactly same algorithm as for drawing lines + // i.e. kinda duplicated code. + float markpow = pow(paramsPerDim,2.0); + for(int p = 0; p < paramBitDepth; p++){ + + double gridSize = pow(markpow,p); + double divsr = size.x / gridSize; + + // return the spacing + if( ofGetWidth()/divsr >= smallestGridSpacing){ + interpLevel = p; + return p; + } + } + interpLevel = 0; + return 0; + }else{ + interpLevel = 0; + return 0; // ??? + } +} +//-------------------------------------------------------------- +void Grid::draw(){ + if(interpolateMode == NO_INTERPOLATION){ + drawGridLines(); + drawPresets(); + }else if(interpolateMode == INTERPOLATE_GRID){ + // calculate according to smallest gridlines + drawGridLines(); + + }else if(interpolateMode == INTERPOLATE_PRESET){ + drawPresets(); + return; // ??? + } + + + + // draw centre cross hairs + drawCrossHairs(); + + + // draw the undo history trail, given viewing area + eventLogger.drawTrail(topLeft, topLeft + size); +} //-------------------------------------------------------------- -void Grid::draw(){ // draw lines +void Grid::drawGridLines(){ // draw lines // TODO too friggin long pixSize.setCoord(ofGetWidth(), ofGetHeight()); // incase of rotation? - //scale++; - // nice loopy thing + int power = 0; // these get big! @@ -82,24 +134,25 @@ float alpha; bool done = false; - float markpow = 32.0; // power that denotes next grid markings + float markpow = 1 << paramsPerDim; // power that denotes next grid markings e.g. 32 int lineWidth = 0; int colCycle = 0; - // loop thru powers of (base?) to determine which should be shown as grids + // loop thru powers of (base?) smallest to biggest + // to determine which should be shown as grids while (!done){ gridSize = pow(markpow,power); - colCycle = power % 7; + colCycle = power % paramBitDepth; divsr = size.x / gridSize; // if (divisor i.e. number of lines is less than 1000 - if( divsr >= 1 && divsr < 700){ + if( ofGetWidth()/divsr >= smallestGridSpacing){ // calculate transparency - float visCont = log10(divsr); // 0 if only 1 line, 3 if 1000 lines + float visCont = log10(divsr*2); // 0 if only 1 line, 3 if 1000 lines alpha = 90*(3 - visCont); ofSetLineWidth(lineWidth); @@ -199,24 +252,21 @@ } - }else if (divsr < 1){ - // ignore... + } + /*else if (divsr < 1){ + // maximum only one line. worth checking so that bigger lines still show up? done = true; } - +*/ power++; + if(power > paramBitDepth) + done = true; + } //cout << "draw done" << "\n"; //displayInfo(); - drawPresets(); - // draw centre cross hairs - drawCrossHairs(); - - - // draw the undo history trail, given viewing area - eventLogger.drawTrail(topLeft, topLeft + size); ////////-------//////// /* @@ -353,6 +403,7 @@ viewWasChanged(); + calculateInterpolateLevel(); eventLogger.logEvent(ZOOM, centre, scale); } @@ -422,7 +473,11 @@ if(snapped){ params = calculateParamsFromCoord(snapCentre); }else{ - params = calculateParamsFromCoord(centre); + if(interpolateMode == NO_INTERPOLATION){ + params = calculateParamsFromCoord(centre); + }else if(interpolateMode == INTERPOLATE_GRID){ + params = calculateInterpolatedParamsFromCoord(centre); + } } for(int i = 0;i<2*paramsPerDim;i++){ midiCC[i] = params[i]; @@ -546,7 +601,7 @@ //-------------------------------------------------------------- #pragma mark const utils -TwoVector Grid::calculateCoordFromParams(vector params) const{ +TwoVector Grid::calculateCoordFromParams(vector params){ vector ccValueX(paramsPerDim); vector ccValueY(paramsPerDim); @@ -562,7 +617,7 @@ } //-------------------------------------------------------------- -vector Grid::calculateParamsFromCoord(TwoVector coord) const{ +vector Grid::calculateParamsFromCoord(TwoVector coord){ if (coord.x > maxValue || coord.y > maxValue){ cout << "calculateParams Error: centre double value is too large" << "\n"; @@ -588,7 +643,59 @@ result.insert( result.end(), resultY.begin(), resultY.end() ); return result; } +//-------------------------------------------------------------- +vector Grid::calculateInterpolatedParamsFromCoord(TwoVector coord){ + vector result; + // round by masking according to interpLevel + + long long x = coord.x; + long long y = coord.y; + cout << interpLevel << "\n"; + int roundDigits = (paramsPerDim*interpLevel); + // knock off last digits + x = x >> roundDigits; + x = x << roundDigits; + float frac = (coord.x - x)/(1 << roundDigits); + long long xlower = x; + long long xupper = x + (1 << roundDigits); + + vector pupper = hilbert.calculateParamsFromIndex(xupper); + vector plower = hilbert.calculateParamsFromIndex(xlower); + + result = interpVector(pupper,plower,frac); +// now Y + y = y >> roundDigits; + y = y << roundDigits; + frac = (coord.y - y)/(1 << roundDigits); + long long ylower = y; + long long yupper = y + (1 << roundDigits); + + pupper = hilbert.calculateParamsFromIndex(yupper); + plower = hilbert.calculateParamsFromIndex(ylower); + + vector resultY = interpVector(pupper,plower,frac); +// stickem together + result.insert( result.end(), resultY.begin(), resultY.end() ); + return result; +} +//-------------------------------------------------------------- +vector Grid::interpVector(vector upper, vector lower, float frac){ + vector result; + if(upper.size() != lower.size()){ + cout << "Error: interpVector takes vectors of same length" << "\n"; + return result; + } + if(frac > 1){ + cout << "Error: bad fraction for vector interpolation" << "\n"; + return result; + } + int N = upper.size(); + for(int i=0; i Grid::walkDiff(vector left, vector right){ // horrible diff -r a42903c61558 -r 8ed7522deaaa hilbert.h --- a/hilbert.h Tue Apr 09 13:22:28 2013 +0100 +++ b/hilbert.h Tue Apr 09 17:14:31 2013 +0100 @@ -19,8 +19,6 @@ class Hilbert{ private: - -public: int P; // dimensionas of high D space int N; // number of resolution bits int codeLength; @@ -29,13 +27,17 @@ vector > theGrayCode; vector theGrayCodeD; - void init(int N, int P); + void makeCode(); - vector calculateParamsFromIndex(unsigned long long coord); - unsigned long long calculateIndexFromParams(vector params); + void makeRotationRules(); int rotate(int vertex, int entryPoint, int direction); int rotateInverse(int vertex, int entryPoint, int direction) ; +public: + void init(int N, int P); + vector calculateParamsFromIndex(unsigned long long coord); + unsigned long long calculateIndexFromParams(vector params); + }; diff -r a42903c61558 -r 8ed7522deaaa presetManager.mm --- a/presetManager.mm Tue Apr 09 13:22:28 2013 +0100 +++ b/presetManager.mm Tue Apr 09 17:14:31 2013 +0100 @@ -195,6 +195,8 @@ } */ // hmm shouldn't have to know about eventlogger and grid view... + // TODO get coord might be wrong if in interpolation mode + thePresets.push_back(new Preset(theGridView.getCoord(), name,nextID, eventLogger.userName, eventLogger.deviceID)); eventLogger.logEvent(SAVE_PRESET, theGridView.getCoord()); // poke grid view to get it to show details diff -r a42903c61558 -r 8ed7522deaaa testApp.mm --- a/testApp.mm Tue Apr 09 13:22:28 2013 +0100 +++ b/testApp.mm Tue Apr 09 17:14:31 2013 +0100 @@ -19,13 +19,13 @@ //-------------------------------------------------------------- void testApp::setup(){ paused = true; - - + + ofBackground( 0, 0, 0 ); ofEnableAlphaBlending(); currentSequence = 0; //ofEnableSmoothing(); - + // open an outgoing connection to HOST:PORT for OSC sender.setup( OSC_HOST, OSC_PORT ); @@ -57,7 +57,12 @@ ofxiPhoneSetOrientation( OFXIPHONE_ORIENTATION_PORTRAIT ); // do this before setting up all the other objects - + /* + sliderViewController = [[SliderViewController alloc] initWithNibName:@"SliderViewController" bundle:nil]; + [ofxiPhoneGetGLParentView() addSubview:sliderViewController.view]; + [sliderViewController setAppRef:(id)this]; + sliderViewController.view.frame = CGRectMake(0,getHeight()-43 - 363,getWidth(),363); + */ // initialise the interfaces theGridView.init(); @@ -68,7 +73,7 @@ for(int i=0; i<10;i++){ sliderVals.push_back(64); } - + // initialise PD int ticksPerBuffer = 8; // 8 * 64 = buffer len of 512 @@ -79,8 +84,8 @@ // setup OF sound stream ofSoundStreamSetup(2, 1, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3); - - + + // set up iOS gui stuff bottomTabViewController = [[BottomTabViewController alloc] initWithNibName:@"BottomTabViewController" bundle:nil]; [ofxiPhoneGetGLParentView() addSubview:bottomTabViewController.view]; @@ -88,7 +93,7 @@ [bottomTabViewController setAppRef:(id)this]; bottomTabViewController.view.frame = CGRectMake(0,getHeight()-44,getWidth(),44); bottomTabViewController.view.hidden = YES; - + ///// topButtonViewController = [[TopButtonViewController alloc] initWithNibName:@"TopButtonViewController" bundle:nil]; @@ -105,15 +110,7 @@ helpViewController.view.hidden = YES; - sliderViewController = [[SliderViewController alloc] initWithNibName:@"SLiderViewController" bundle:nil]; - [ofxiPhoneGetGLParentView() addSubview:sliderViewController.view]; - - [sliderViewController setAppRef:(id)this]; - [sliderViewController show:(id)this]; - sliderViewController.view.frame = CGRectMake(0,getHeight()-43 - 363,getWidth(),44); - - // load preset sequences loadSequences(); @@ -125,7 +122,7 @@ // timer.init(); whichInterfaceShowing = BOTH; // but timer will change this - + if(eventLogger.questionnaireCompleted){ [bottomTabViewController show:(id)this withSelection:1]; @@ -133,21 +130,22 @@ setAllGUISliders(theGridView.getParams()); // GO paused = false; - + randomise(); // everyone starts from random position (or where they left off??) ofxiPhoneExternalDisplay::mirrorOn(); - + + //[sliderViewController show:(id)this]; } //-------------------------------------------------------------- void testApp::exit(){ - + presetManager.exitAndSaveAll(); eventLogger.exitAndSave(); - + core.exit(); // are these handled automatically? @@ -156,7 +154,7 @@ //[bottomTabViewController release]; delete sliderGUI; - + cout << "exit done \n"; } @@ -209,9 +207,9 @@ //-------------------------------------------------------------- void testApp::showQuestionnaire(){ // stop updating / drawing - + // if(eventLogger.questionnaireCompleted) return; - + [topButtonViewController pausePressed:(id)this]; //stopSequencer @@ -225,18 +223,18 @@ whichInterfaceShowing = QUESTIONNAIRE; - + } //-------------------------------------------------------------- void testApp::questionnaireHidden(vector answers, const char* userComments){ // send answers to server as json eventLogger.questionnaireAnswersObtained(answers, userComments); - + // tell bottomtabviewcontroller to show and select both interface interfaceSelected(BOTH); [bottomTabViewController show:(id)this withSelection:1]; - + } //-------------------------------------------------------------- // shortcut function for testing @@ -247,9 +245,9 @@ } //-------------------------------------------------------------- void testApp::showIntro(){ - + cout << "SHOW INTRO\n"; - + [tsc cancelTimers]; bottomTabViewController.view.hidden = YES; introViewController = [[IntroViewController alloc] initWithNibName:@"IntroViewController" bundle:nil]; @@ -282,7 +280,7 @@ void testApp::interfaceSelected(int which){ switch (which){ case 0: - + whichInterfaceShowing = SLIDERS; sliderGUI->setVisible(true); // set the slider values to stuff got from zoomer @@ -291,7 +289,7 @@ break; case 1: - + whichInterfaceShowing = BOTH; sliderGUI->setVisible(true); // set the slider values to stuff got from zoomer @@ -299,7 +297,7 @@ setAllGUISliders(sliderVals); break; case 2: - + sliderGUI->setVisible(false); whichInterfaceShowing = ZOOMER; break; @@ -321,10 +319,10 @@ float dim = (height-10.0*OFX_UI_GLOBAL_WIDGET_SPACING)/10.0; // LEFT GUI sliderGUI = new ofxUICanvas(0,160,SLIDER_GUI_WIDTH,getHeight()); - + // Uh.. loop this for(int i = 1; i<=10;i++){ - + ofxUISlider *slider; slider = (ofxUISlider *)sliderGUI->addWidgetDown(new ofxUISlider(length,dim,0.0,127,64,sliderParamNames[i-1])); slider->setDrawPadding(true); @@ -340,10 +338,10 @@ sliders.push_back(slider); } - + ofAddListener(sliderGUI->newGUIEvent, this, &testApp::sliderGUIEvent); - + } //-------------------------------------------------------------- void testApp::sliderGUIEvent(ofxUIEventArgs &e){ @@ -351,7 +349,7 @@ cout << "GUI ERROR"; return; } - + // "normal" parameter changes for(int i = 1; i<=10;i++){ @@ -362,14 +360,14 @@ sliderMoved(i-1,slider->getScaledValue()); // internal array 0 indexed } } - + } //-------------------------------------------------------------- void testApp::sliderMoved(int which, float value){ // an update caused by slider view being touched sliderVals[which] = (int)value; theGridView.setParams(sliderVals); - + sendParametersToPD(); eventLogger.logEvent(CHANGE_SLIDER, TwoVector(),0.0,which , value); @@ -391,7 +389,7 @@ sliderVals[i] = ofRandom(0, 127); } - + currentSequence = ofRandom(0, sequences.size()-1); // send to grid, sliders and PD theGridView.setParams(sliderVals); setAllGUISliders(sliderVals); @@ -423,35 +421,47 @@ } //-------------------------------------------------------------- void testApp::sendParametersToPD(){ + static int previousSequence; + // frequencer stuff to get 16 steps - // frequencer stuff to get 16 steps + vector vals; + + + vals.push_back((sliderVals[0]+32)*8.); // DC offset + for(int i=1; i<5;i++){ + vals.push_back((sliderVals[i] - 64)*2.); + } + + vector steps = frequencer.freqMagEdit(freqIndexes, vals); + List seqSteps; + seqSteps.addSymbol("seqSteps"); + for(int i=0; i < 16; i++){ + seqSteps.addFloat(round(steps[i])); + } + core.pd.sendList("fromOF", seqSteps); + /* - vector vals; - - - vals.push_back((sliderVals[0]+32)*8.); // DC offset - for(int i=1; i<5;i++){ - vals.push_back((sliderVals[i] - 64)*2.); + if(currentSequence != previousSequence){ + List seqSteps; + + seqSteps.addSymbol("seqSteps"); + if(currentSequence >= sequences.size() || currentSequence < 0){ + cout << "ERROR: not a valid sequence index\n"; + for(int i=0; i < 16; i++){ + seqSteps.addFloat(50); + } + }else{ + for(int i=0; i < 16; i++){ + seqSteps.addFloat(round(sequences[currentSequence][i])); + } + } + + core.pd.sendList("fromOF", seqSteps); + previousSequence = currentSequence; } - - vector steps = frequencer.freqMagEdit(freqIndexes, vals); - */ - // send a list using the List object - List seqSteps; - - seqSteps.addSymbol("seqSteps"); - if(currentSequence > sequences.size() || currentSequence < 0){ - cout << "ERROR: not a valid sequence index\n"; - } - for(int i=0; i < 16; i++){ - seqSteps.addFloat(round(sequences[currentSequence][i])); // rounding here?? - } - - - core.pd.sendList("fromOF", seqSteps); - + // send synth params sendOscShape(sliderVals[5]); sendFiltType(sliderVals[6]); sendFiltFreq(sliderVals[7]); @@ -467,7 +477,7 @@ #pragma mark STANDARD OF FUNCTIONS //-------------------------------------------------------------- void testApp::update(){ - + if(paused) return; if(ofxiPhoneExternalDisplay::isExternalScreenConnected()){ @@ -487,11 +497,8 @@ zoomVel = zoomVel*slowFactor; moveVel.setCoord(0.0,0.0);; // don't move if zooming! Too many events! - // need to do this if zoom goes to snap - if(theGridView.snapped){ - setAllGUISliders(theGridView.getParams()); - sendParametersToPD(); - } + setAllGUISliders(theGridView.getParams()); + sendParametersToPD(); } if(moveVel.norm() > 0.3){ @@ -502,7 +509,7 @@ theGridView.move(moveVel); moveVel = moveVel*slowFactor; } - // and get new parameter values + // and get new parameter values setAllGUISliders(theGridView.getParams()); sendParametersToPD(); }else if(moveVel.norm() > 0.01){ // and less than 0.3 @@ -515,9 +522,9 @@ }else{ // stopped - do nothing } - + } - + } //-------------------------------------------------------------- void testApp::sendOSCParams(){ @@ -537,18 +544,18 @@ } //-------------------------------------------------------------- void testApp::draw(){ - + switch (whichInterfaceShowing){ case SLIDERS: break; case ZOOMER: theGridView.draw(); - + break; case BOTH: theGridView.draw(); - + break; case INTRO: break; @@ -572,7 +579,7 @@ numActiveTouches++; preventingMovePostScroll = false; - + if(touch.id == 0){ touch0.setCoord(touch.x,touch.y); prevTouch0 = touch0; @@ -596,7 +603,7 @@ double dist = touch1.distanceTo(touch0); prevDist = dist; } - + } //-------------------------------------------------------------- @@ -611,7 +618,7 @@ } // otherwise we're good to let the zoomer handle touch - + // which one? keep track of each touch point if(touch.id == 0){ touch0.setCoord(touch.x,touch.y); @@ -620,7 +627,7 @@ touch1.setCoord(touch.x,touch.y); } - + if(numActiveTouches == 1){ if(preventingMovePostScroll) return; handleScroll(); @@ -629,14 +636,14 @@ } prevTouch0 = touch0; - + } //-------------------------------------------------------------- // handle a finger being dragged void testApp::handleScroll(){ - + TwoVector move = touch0 - prevTouch0; if(yLocked){ move.y = 0.0; @@ -644,7 +651,7 @@ if(xLocked){ move.x = 0.0; } - + // check time since last move - if unsigned int moveTime = ofGetSystemTimeMicros(); if(moveTime - lastMoveTime > 100000){ @@ -655,11 +662,11 @@ } lastMoveTime = moveTime; - + prevMove2 = prevMove; prevMove = move; - + theGridView.move(move); // and get new parameter values @@ -687,12 +694,11 @@ prevDist = dist; - // need to do this if zoom goes to snap - if(theGridView.snapped){ - setAllGUISliders(theGridView.getParams()); - sendParametersToPD(); - } + setAllGUISliders(theGridView.getParams()); + sendParametersToPD(); + + } //-------------------------------------------------------------- void testApp::touchUp(ofTouchEventArgs &touch){ @@ -706,7 +712,7 @@ }// otherwise we're good to let the zoomer handle touch - + // which one? if(touch.id == 0){ // tricky situation - we tried to zoom but may have left non-move finger on @@ -714,7 +720,7 @@ }else if(touch.id == 1){ - + prevTouch1.setCoord(0,0); } @@ -734,7 +740,7 @@ // can be bad if moved so create special mode to stop scroll (special modes bad!) preventingMovePostScroll = true; } - + } //-------------------------------------------------------------- @@ -742,55 +748,55 @@ // preset? /* ballses everything for some reason - TwoVector centre = TwoVector(getWidth()*0.5,getHeight()*0.5); - // if near centre - if((touch.x < centre.x+10) && (touch.x > centre.x-10) && (touch.y < centre.y+10) && (touch.y > centre.y-10)){ - numActiveTouches = 0; // dirty - presetManager.showNameDialog(); - - } + TwoVector centre = TwoVector(getWidth()*0.5,getHeight()*0.5); + // if near centre + if((touch.x < centre.x+10) && (touch.x > centre.x-10) && (touch.y < centre.y+10) && (touch.y > centre.y-10)){ + numActiveTouches = 0; // dirty + presetManager.showNameDialog(); + + } */ } //-------------------------------------------------------------- void testApp::lostFocus(){ - + } //-------------------------------------------------------------- void testApp::gotFocus(){ - + } //-------------------------------------------------------------- void testApp::gotMemoryWarning(){ - + } //-------------------------------------------------------------- void testApp::deviceOrientationChanged(int newOrientation){ -/* - cout << "orientation: " << newOrientation; - - if(newOrientation == 4){ - ofxiPhoneSetOrientation( OF_ORIENTATION_DEFAULT ); - - }else if(newOrientation == 3){ - ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT ); - }else if(newOrientation == 3){ - ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT ); - } - - - [ofxiPhoneGetGLView() updateDimensions]; -*/ + /* + cout << "orientation: " << newOrientation; + + if(newOrientation == 4){ + ofxiPhoneSetOrientation( OF_ORIENTATION_DEFAULT ); + + }else if(newOrientation == 3){ + ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT ); + }else if(newOrientation == 3){ + ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT ); + } + + + [ofxiPhoneGetGLView() updateDimensions]; + */ } //-------------------------------------------------------------- void testApp::touchCancelled(ofTouchEventArgs& args){ - + } //--------------------------------------------------------------- // AUDIO STUFF @@ -848,11 +854,11 @@ float ctrlSmoother(float newsamp){ static float x1,x2,y1,y2; float x0, y0; - + x0 = newsamp; - + y0 = fB[0]*x0 + fB[1]*x1 + fB[2]*x2 - fA[1]*y1 - fA[2]*y2; - + // shift x2 = x1; x1 = x0; @@ -874,12 +880,12 @@ float ctrlout[numcontrols]; string ctrlName[5] = {"pWidth" , "sqVol", "sawVol", "sineVol", "FMAmt"}; float values[5][5] = - {{0.5, 0., 0., 1., 1.}, // 0 - {0.5, 0., 0., 1., 0.}, // 32 + {{0.5, 0., 0., 1., 1.}, // 0 + {0.5, 0., 0., 1., 0.}, // 32 {0.5, 0., 1., 0., 0.}, // 64 {0.5, 1., 1., 0., 0.}, // 96 {0.01,1., 1., 0., 0.}}; // 127 - + float fidx = (numpoints-1)*ctrlin/128.; int idx = floor(fidx); float frac = fidx - idx; @@ -890,7 +896,7 @@ toPD.addSymbol(ctrlName[i]); toPD.addFloat(ctrlout[i]); // rounding here?? - + core.pd.sendList("fromOF", toPD); //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n"; } @@ -908,7 +914,7 @@ float ctrlout[numcontrols]; string ctrlName[4] = {"lpLev" , "bpLev", "hpLev", "reson"}; float values[3][4] = - {{2., 0., 0., 1.}, // 0 + {{2., 0., 0., 1.}, // 0 {0., 10., 0., 10.}, // 64 {0., 0., 1., 1.}}; // 127 @@ -940,7 +946,7 @@ List toPD; toPD.addSymbol("filtFreq"); - toPD.addFloat(fout); + toPD.addFloat(fout); core.pd.sendList("fromOF", toPD); } @@ -956,7 +962,7 @@ float ctrlout[numcontrols]; string ctrlName[3] = {"attack" , "decay", "sustain"}; float values[5][3] = - {{0., 0., 0.}, // 0 + {{0., 0., 0.}, // 0 {0., 0.5, 0.}, // 32 {0.0, 1., 0.8}, // 64 {0.99, 0.3, 0.}, // 96 @@ -1041,10 +1047,10 @@ // read in sequence preset file string jsonFile = ofxiPhoneGetDocumentsDirectory() + "pilot_sequences.json"; - + Json::Value root; Json::Reader reader; - + ifstream theFile(jsonFile.c_str()); stringstream fileText; string line; @@ -1056,7 +1062,7 @@ while(theFile){ theFile >> line; // cout << line << "\n"; // lots? - fileText << line; + fileText << line; } theFile.close(); @@ -1082,6 +1088,7 @@ } } // currentSequence - currentSequence = ofRandom(0,N); + + currentSequence = ofRandom(0,N-1); }