Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7020607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:20:25+00:00 2026-05-27T23:20:25+00:00

I wish my first post wasn’t so newbie. I’ve been working with openframeworks, so

  • 0

I wish my first post wasn’t so newbie. I’ve been working with openframeworks, so far so good, but as I’m new to programming I’m having a real headache returning the right value from an int function. I would like the int to increment up until the Boolean condition is met and then decrement to zero. The int is used to move through an array from beginning to end and then back. When I put the guts of the function into the method that I’m using the int in, everything works perfectly, but very messy and I wonder how computationally expensive it is to put there, it just seems that my syntactic abilities are lacking to do otherwise. Advice appreciated, and thanks in advance.

int testApp::updown(int j){

if(j==0){
    arp =true;

}
else if (j==7){
    arp = false; 

}

if(arp == true){
    j++;

}

else if(arp == false){
    j--;

}

    return (j);

}

and then its called like this in an audioRequest block of the library I’m working with:

for (int i = 0; i < bufferSize; i++){


 if ((int)timer.phasor(sorSpeed)) {

            z = updown(_j);
            noteOut = notes [z];

            cout<<arp;
            cout<<z;

        }

EDIT: For addition of some information. Removed the last condition of the second if statement, it was there because I was experiencing strange happenings where j would start walking off the end of the array.

Excerpt of testApp.h

int z, _j=0;
Boolean arp;

EDIT 2: I’ve revised this now, it works, apologies for asking something so rudimentary and with such terrible code to go with. I do appreciate the time that people have taken to comment here. Here are my revised .cpp and my .h files for your perusal. Thanks again.

#include "testApp.h"
#include <iostream>
using namespace std;



testApp::~testApp() {

}

void testApp::setup(){


sampleRate          = 44100;
initialBufferSize   = 1024;

//MidiIn.openPort();
//ofAddListener(MidiIn.newMessageEvent, this, &testApp::newMessage);

j = 0;
z= 0;
state = 1;


tuning = 440;
inputNote = 127;
octave = 4;
sorSpeed = 2;
freqOut = (tuning/32) * pow(2,(inputNote-69)/12);
finalOut = freqOut * octave;



notes[7] = finalOut+640;
notes[6] = finalOut+320;
notes[5] = finalOut+160; 
notes[4] = finalOut+840;
notes[3] = finalOut+160;
notes[2] = finalOut+500;
notes[1] = finalOut+240;
notes[0] = finalOut;


ofSoundStreamSetup(2,0,this, sampleRate, initialBufferSize, 4);/* Call this last ! */


}

void testApp::update(){



}

void testApp::draw(){



}

int testApp::updown(int &_j){

int tmp;

if(_j==0){
    arp = true;
}

else if(_j==7) {
    arp = false; 
}


if(arp == true){
    _j++;
}

else if(arp == false){
    _j--;
}

tmp = _j;
return (tmp);

}

void testApp::audioRequested    (float * output, int bufferSize, int nChannels){


    for (int i = 0; i < bufferSize; i++){


        if ((int)timer.phasor(sorSpeed)) {


            noteOut = notes [updown(z)];


            }


    mymix.stereo(mySine.sinewave(noteOut),outputs,0.5);


    output[i*nChannels    ] = outputs[0]; 
    output[i*nChannels + 1] = outputs[1];

    }
}

testApp.h

class testApp : public ofBaseApp{

public:
    ~testApp();/* destructor is very useful */
    void setup();
    void update();
    void draw();

    void keyPressed  (int key);
    void keyReleased(int key);
    void mouseMoved(int x, int y );
    void mouseDragged(int x, int y, int button);
    void mousePressed(int x, int y, int button);
    void mouseReleased(int x, int y, int button);
    void windowResized(int w, int h);
    void dragEvent(ofDragInfo dragInfo);
    void gotMessage(ofMessage msg);

    void newMessage(ofxMidiEventArgs &args);

    ofxMidiIn MidiIn;

    void audioRequested     (float * input, int bufferSize, int nChannels); /* output method */
    void audioReceived  (float * input, int bufferSize, int nChannels); /* input method */

    Boolean arp;
    int     initialBufferSize; /* buffer size */
    int     sampleRate;
    int    updown(int &intVar);


    /* stick you maximilian stuff below */

    double filtered,sample,outputs[2];
    maxiFilter filter1;
    ofxMaxiMix mymix;
    ofxMaxiOsc sine1;
    ofxMaxiSample beats,beat;
    ofxMaxiOsc mySine,myOtherSine,timer;

    int currentCount,lastCount,i,j,z,octave,sorSpeed,state;
    double notes[8];
    double noteOut,freqOut,tuning,finalOut,inputNote;

};

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:20:25+00:00Added an answer on May 27, 2026 at 11:20 pm

    It’s pretty hard to piece this all together. I do think you need to go back to basics a bit, but all the same I think I can explain what is going on.

    1. You initialise _j to 0 and then never modify the value of _j.
    2. You therefore call updown passing 0 as the parameter every time.
    3. updown returns a value of 1 when the input is 0.

    Perhaps you meant to pass z to updown when you call it, but I cannot be sure.

    Are you really declaring global variables in your header file? That’s not good. Try to use local variables and/or parameters as much as possible. Global variables are pretty evil, especially declared in the header file like that!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wish to use Entity Framework Code-first for a new project. So i decided
I wish to know how Old Linux scheduling algorithm SJF (shortest job first) calculates
I wish to test a function that will generate lorem ipsum text, but it
First post on stackoverflow. Hope everything is right! I'm thinking of attaching an ID
Using a linq query/method chainging I wish to select just the first 2 Point
I've been working with the Restlet library for the last couple weeks and from
I wish to change the first character from a 'U' to an 'S' in
(Note - this is a re-post as my first question got posted under wrong
First I need to apologize for the long post, I struggle with being overly
I'm using constructor injection for the first time and wish to write my code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.