TonicAudio / Tonic

Easy and efficient audio synthesis in C++
The Unlicense
524 stars 63 forks source link

Function for getting a specific parameter. #250

Closed iY0Yi closed 9 years ago

iY0Yi commented 9 years ago

Hi. I love Tonic. Thanks.

I want to know a ADSR's trigger value. I know the getParameters. But I want to know the value directly.

How do you think about implementation of the function? Are there any problems?

Cheers!

Currently, I use a function like this:

bool getTriggerState(int id){
        vector<ControlParameter>params = getParameters();
        string tname = "trigger"+toStr(id);
        bool state = false;
        for(int i = 0; i < params.size(); i++){
            ControlParameter param = params[i];
            string pname = param.getName();
            if (pname == tname) {
                state = bool(param.getValue());
                break;
            }
        }
        return state;
    }

string toStr(int s){
        std::stringstream ss;
        ss << s;
        std::string str;
        ss >> str;
        return str;
    }
iY0Yi commented 9 years ago

I couldn't get the state(sound is playing or finished) of ADSR by the code. So, maybe this issue is useless... I will post this as question on google group. Thanks.

iY0Yi commented 9 years ago

Sorry for reopening this issue. I found a similar issue. https://github.com/TonicAudio/Tonic/issues/184 Do you have a plan for ADSR.finished() function?

I have a synths pool. I wanna reuse synths. Cheers!

morganpackard commented 9 years ago

Hi goro, Thanks for your thoughtful emails. We haven't implemented finished( ) simply because we haven't needed it for any projects we're working on. Do you want to try doing it yourself and submitting a pull request (to the development branch). It's a simple change but I can't promise how quickly we'll be able to get to it. -Morgan

On Saturday, December 27, 2014, Goro Matsumoto notifications@github.com wrote:

Sorry for reopening this issue. I found a similar issue.

184 https://github.com/TonicAudio/Tonic/issues/184

Do you have a plan for ADSR.finished() function?

Reply to this email directly or view it on GitHub https://github.com/TonicAudio/Tonic/issues/250#issuecomment-68172988.

Morgan Packard Programmer + Designer

234 Broadway, Suite 1 Cambridge, MA 02139 617 661 6680

iY0Yi commented 9 years ago

Thanks for your response. Now I solved this problem by tweening the sound volume instead of ADSR, with ofxTweenzor addon. https://github.com/NickHardeman/ofxTweenzor

I think my case is rare for other people, so I should not implement it. And enveloping with the addon is not so bad:)

Anyway, thanks for your great library! Cheers!

morganpackard commented 9 years ago

Glad you got something to work. I do think that ADSR::finished() would be useful to lots of people in the future. Maybe I'll add it in the coming weeks. Also, you might be interested in ControlCallback in the main tonic repo (not in ofxTonic yet). It allows some great flexibility with lambda functions. Requires c++11 which is why it's not in ofxTonic yet.