[Coding] [SOLVED] try to add one function :-) Help!

Hello,

I am trying to add a function (RANDOM) that makes voice1 randomly.
to do so, I added a MENU (menu.c, etc). It is okay, I see the menu in the LCD :-)

Next, I added a section in the MIDI PARSER.C :
// rstephane : Handle the RND button
            case CC2_RND_DRUM1:
                // initDrumVoice();   
                //clear upper nibble
                voiceArray[0].osc.midiFreq &= 0x00ff;
                //set upper nibble
                voiceArray[0].osc.midiFreq |= msg.data2 << 8;
                osc_recalcFreq(&voiceArray[0].osc);   
                break;
                       
I declared the CC2.. stuff :-)

I comiled successfully, but when I turn my RND knob, nothing happenness !
However, if for instance, I take one of the code:

case CC2_MUTE_7:
            {
                const uint8_t voiceNr = msg.data1 - CC2_MUTE_1;
                if(msg.data2 == 0)
                {
                    seq_setMute(voiceNr,0);
                }
                else
                {
                    seq_setMute(voiceNr,1);
                }

            }

and modify it: I works :-)

so I suppose switch() case  CC2_RND_DRUM1: is not working...

I don't kno why?
perhaps I am totally wrong on the way, I program?
can you help?
Cheers (a dummy guy who is desesperate ;-) )

bye!

Comments

  • edited May 2014
    how have you defined the RND_DRUM1 parameter on the AVR side?


    in menu.c -> menu_parseKnobValue(...)
    the 4pots are processed.

    at the end of the function you have:


            if(paramNr<128) // => Sound Parameter below 128
                frontPanel_sendData(MIDI_CC,(uint8_t)paramNr,dtypeValue);
            else if(paramNr>=128 && (paramNr < END_OF_SOUND_PARAMETERS)) // => Sound Parameter above 127
                frontPanel_sendData(CC_2,(uint8_t)(paramNr-128),dtypeValue);
            else
                menu_parseGlobalParam(paramNr,dtypeValue);
            break;


    so if your parameter numer defined in the parameter array is higher than 127 it is send to the mainboard with the CC_2 prefix, which calls the midiParser_ccHandler code on the mainboard.
  • Hello and thx :-) I will check those parts. I noticed them late yesterday while trying to understand the code.. I have this CC_2... but then I don't understand as I defined an CC2_RND_VOICE1 parameter like the other parameters which are above 127 .. anyhow, let me look at the code and come back to you with more questions ;-))))
  • edited May 2014
    the CC2_RND_VOICE1 define in the cortex code has to be on the same position in the list as the PAR_RND_VOICE1 parameter in the enum ParamEnums in the AVR code (parameters.h).
  • edited May 2014
    julian,
    thanks ! i will  check this :-)

  • edited May 2014
    oki , I checked the code and in midimessage.c I have
        //Mute Button NRPN messages
        CC2_MUTE_1 = 200,
        CC2_MUTE_2,
        CC2_MUTE_3,
        CC2_MUTE_4,
        CC2_MUTE_5,
        CC2_MUTE_6,
        CC2_MUTE_7,
       
        // rstephane : RND button :-) for CASE switch in MidiParser.C
        CC2_RND_DRUM1,   // Position 207

    }Param2Enums;

    and then if I look at my file parameters.h :

        PAR_BAR_RESET_MODE,                    // bool --AS 0 or 1   /*270*/
        PAR_MIDI_CHAN_GLOBAL,                // --AS global midi channel
        PAR_RND_VOICE1,                    // rstephane: random drum1  ---> position  272
        NUM_PARAMS   
    };

    is it what I should look at, if so i see that PAR_RND_VOICE1 is not at the same position (272 vs 207), no?



  • while i am writing this posty, i notice a spelling mistake , i do it again:

    oki , I checked the code and in midimessage.c I have
        //Mute Button NRPN messages
        CC2_MUTE_1 = 200,
        CC2_MUTE_2,
        CC2_MUTE_3,
        CC2_MUTE_4,
        CC2_MUTE_5,
        CC2_MUTE_6,
        CC2_MUTE_7,
       
        // rstephane : RND button for CASE switch in MidiParser.C
        CC2_RND_VOICE1,   // Position 207

    }Param2Enums;

    and then if I look at my file parameters.h :

        PAR_BAR_RESET_MODE,                    // bool --AS 0 or 1   /*270*/
        PAR_MIDI_CHAN_GLOBAL,                // --AS global midi channel
        PAR_RND_VOICE1,                    // rstephane: random drum1  ---> position  272
        NUM_PARAMS   
    };

    is it what I should look at, if so i see that PAR_RND_VOICE1 is not at the same position (272 vs 207), no?

  • edited May 2014
    ah i see.

    first of all the parameter list is divided into different sections. marked by the '##########' comment boxes

    first are the sound parameter:
    these are stored/loaded with each kit preset.
    only the sound parameters are send out as CC_... and CC2_... messages automatically to the mainboard
    so to add one to CC2_... you have to insert your PAR_RND... after PAR_MIDI_NOTE7

    Then there is the ######## End of sound Parameters ######## section:
    these are working variables that are not saved anywhere

    then the ######## Global Parameters ##############
    these are not saved with the kit, but in the global savefile. Intended for global settings like BPM, screensaver on/off etc.



    As for the MidiMessages.h file
    you should also add you CC2_RND... after CC2_MIDI_NOTE7

    the CC2_MUTE_x are a special case and are deliberately put at the end of the list since they are not used by the LXR engine internally, but only come into play so the voice muting can be accessed by external NRPN messages. Thats why there is this big offset between CC2_MIDI_NOTE7 (~111) and CC2_MUTE_1 (200)

    these are most of the time special cases that handled in menu.c->menu_parseGlobalParam(...) and are not send automatically. you have to add a special handler to menu_parseGlobalParam(..) to send them to the mainboard
  • oki, i start to understand a bit better, and now that I made the changes you mentionned, I get my function working while I turn my new RND knob :-)
    I continue and come to you asap with more questions. I will also try to explain what I did for other to add their own simple function (I am not a goog programmer). :-)
  • I am not a goog programmer
    me neither, but we all are learning :)
  • works fine now!
    Thx !!!!!!!!!!!!!!!
  • i will now start a little tuto :-)
  • edited May 2014
    maybe do it in the wiki?

    wiki.sonic-potions.com

    .oO(I know i have to finally publish the address better)
  • oh yes ! good idea.

    by the way, I think that you can update certain wiki's system from GITHUB direclty :-)

    We did this for another project called poppy -> http://wiki.poppy-project.org/
    explanation: while I am on the poppy git hub branch... I can update some pages (special branch dedicated to the mediawiki) on the GITHUB and then I see the update of those pages on the wiki as soon as I commit :-)
    it is very good, as you can make a file dedicated to install instructions, tuto to build a new function, etc... you update information on a centralized platform that is also P2P (GIT)... so I can also update when I am off (no network).

    Another good point is that you can use PROSE.IO website to update the GITHUB (and thus WIKI). PROSE is an WYSIWYG editor for GIT and thus the WIKI.

    I don't if I am clear, if you interested , I can give you more info. I am not sure that your mediawiki supports the gIT hub plug in (I need to check your version versus poppy wiki... grrrrrr !!!!).

    tell me ;-)
  • hmm nice idea to integrate github to the wiki.
    gotta do some research if this is possible with mediawiki, too.
    I chose mediawiki because I found a plugin to export the open office manual directly to mediawiki ;)


    poppy looks really great!
    image
  • it seems there is an extension
    https://github.com/JeroenDeDauw/GitHub/blob/master/README.md

    I'll first try to fix the images in the manual and the formatting in the wiki, then I may have a look at this extension.
  • so things are progressing, my function is well executed when i turn a dedicated knob:

    void randomDrumVoice(const uint8_t voiceNr)
    {
            uint8_t rndData;

            // COARSE
            rndData = (uint8_t) GetRngValue();
            //clear upper nibble
            voiceArray[voiceNr].osc.midiFreq &= 0x00ff;
            //set upper nibble
            voiceArray[voiceNr].osc.midiFreq |= rndData << 8;
            osc_recalcFreq(&voiceArray[voiceNr].osc);
            
            //F_OSCx_FINE: -63 to +63
            // rndDataTemp = GetRngValue(); // value we want to convert
            // old_min = 0;
            // old_max = 4294967294; // 4294967295-1
            // new_min = -63;
            // new_max = 63;
            // rndData =(uint8_t)  (  ( (rndDataTemp - old_min) / (old_max - old_min) ) * (new_max - new_min) + new_min  );
            //clear lower nibble
            // voiceArray[voiceNr].osc.midiFreq &= 0xff00;
            //set lower nibble
            // voiceArray[voiceNr].osc.midiFreq |= rndData;
            // osc_recalcFreq(&voiceArray[voiceNr].osc);
            
            // OSC_WAVE_DRUM1:
            rndData = (uint8_t) GetRngValue()%5; // ( GetRngValue()%(6-0) +0 );
            voiceArray[voiceNr].osc.waveform = rndData;
     
            // CC2_FILTER_TYPE_3:
            rndData = (uint8_t) GetRngValue()%5;
            voiceArray[voiceNr].filterType = rndData+1;
                    
            // FILTER
            rndData = (uint8_t) GetRngValue();
            const float f = rndData/127.f;
            //exponential full range freq
            SVF_directSetFilterValue(&voiceArray[voiceNr].filter,valueShaperF2F(f,FILTER_SHAPER) );
            // RESO
            rndData = (uint8_t) GetRngValue();
            SVF_setReso(&voiceArray[voiceNr].filter, rndData/127.f);

            //VOL_SLOPE1:
            //rndData = (uint8_t) GetRngValue();
            //slopeEg2_setSlope(&voiceArray[voiceNr].oscVolEg,rndData);

            // PITCH_SLOPE1:
            //rndData = (uint8_t) GetRngValue();
            //DecayEg_setSlope(&voiceArray[voiceNr].oscPitchEg,rndData);
            
            
            
            //OSC1_DIST:
            rndData = (uint8_t) GetRngValue();
    #if USE_FILTER_DRIVE
            voiceArray[voiceNr].filter.drive = 0.5f + (rndData/127.f) *6;
    #else
            setDistortionShape(&voiceArray[voiceNr].distortion,rndData);
    #endif        

           ...

    *****
    if you look at what i did, i do the random values in a very very bad manner !!!

    could you help me in trying to convert the random 32 bits unsigned values to -63 + 63 , -1 to +1, 0-127, 0-1-2-3-4 (fylter type).

    a link to a nice tuto about this would be perfect !

    cheers!
Sign In or Register to comment.