Old 01-23-2018, 11:28 AM   #1
fundorin
Banned
 
Join Date: Feb 2014
Location: Moscow, Russia
Posts: 554
Default Soft takeover issue with pan adjustment

I have nearly identical functions for soft takeover adjustment of volume and pan values. The issue is that the volume function is working fine, while pan function stops at midi value 64 (D_PAN value 0), when reaching the center position from either side..

Guess it might be somehow related with the "D_PAN" range, which is -1...1.
Tried GetSetMediaTrack, SetMediaTrack, CSurf_OnPanChange functions. The behavior stays the same.

Conversion functions were taken from Reaper SDK.

Why is it happening?

Code:
static double charToVol(unsigned char val)
{
    double pos = ((double)val*1000.0) / 127.0;
    pos = SLIDER2DB(pos);
    return DB2VAL(pos);

}

static  unsigned char volToChar(double vol)
{
    double d = (DB2SLIDER(VAL2DB(vol))*127.0 / 1000.0);
    if (d < 0.0)d = 0.0;
    else if (d > 127.0)d = 127.0;

    return (unsigned char)(d + 0.5);
}

static double charToPan(unsigned char val)
{
    double pos = ((double)val*1000.0 + 0.5) / 127.0;

    pos = (pos - 500.0) / 500.0;
    if (fabs(pos) < 0.08) pos = 0.0;

    return pos;
}

static unsigned char panToChar(double pan)
{
    pan = (pan + 1.0)*63.5;

    if (pan < 0.0)pan = 0.0;
    else if (pan > 127.0)pan = 127.0;

    return (unsigned char)(pan + 0.5);
}

const int slE[8]{ 120, 121, 122, 123, 124, 125, 126, 127 };        // Encoders
const int slP[8]{ 8,   9,  10,  11,  12,  13,  14,  15 };        // Pots

    void OnMIDIEvent(MIDI_event_t *evt)
    {
        if (evt->midi_message[0] == 0xBF)
        {
            //Faders
            if (slF[0] <= evt->midi_message[1] && evt->midi_message[1] <= slF[7])                         //Faders
            {
                int tid = evt->midi_message[1] - slF[0] + 1;
                MediaTrack *tr = CSurf_TrackFromID(tid, g_csurf_mcpmode);
                int curVal = volToChar(GetMediaTrackInfo_Value(tr, "D_VOL"));
                if (lastF[tid - 1] < curVal && evt->midi_message[2] >= curVal)
                {
                    CSurf_OnVolumeChange(tr, charToVol(evt->midi_message[2]), 0);
                }
                else if (lastF[tid - 1] > curVal && evt->midi_message[2] <= curVal)
                {
                    CSurf_OnVolumeChange(tr, charToVol(evt->midi_message[2]), 0);
                }
                else if (lastF[tid - 1] == curVal)
                {
                    CSurf_OnVolumeChange(tr, charToVol(evt->midi_message[2]), 0);
                }
                lastF[tid - 1] = evt->midi_message[2];
            }

            //Pots
            else if (slP[0] <= evt->midi_message[1] && evt->midi_message[1] <= slP[7])                         //Pots
            {
                int tid = evt->midi_message[1] - slP[0] + 1;
                MediaTrack *tr = CSurf_TrackFromID(tid, g_csurf_mcpmode);
                int curPan = panToChar(GetMediaTrackInfo_Value(tr, "D_PAN"));
                //if (lastP[tid - 1] < curPan && evt->midi_message[2] >= curPan)
                if (lastP[tid - 1] < curPan && evt->midi_message[2] >= curPan)
                {
                    //CSurf_OnPanChange(tr, charToPan(evt->midi_message[2], 0);
                    double amt = charToPan(evt->midi_message[2]);
                    GetSetMediaTrackInfo(tr, "D_PAN", &amt);
                }
                else if (lastP[tid - 1] > curPan && evt->midi_message[2] <= curPan)
                {
                    //CSurf_OnPanChange(tr, charToPan(evt->midi_message[2], 0);
                    double amt = charToPan(evt->midi_message[2]);
                    GetSetMediaTrackInfo(tr, "D_PAN", &amt);
                }
                else if (lastP[tid - 1] == curPan)
                {
                    //CSurf_OnPanChange(tr, charToPan(evt->midi_message[2], 0);
                    double amt = charToPan(evt->midi_message[2]);
                    GetSetMediaTrackInfo(tr, "D_PAN", &amt);
                }
                lastP[tid - 1] = evt->midi_message[2];
            }
        }
    }
fundorin is offline   Reply With Quote
Old 01-26-2018, 05:44 AM   #2
fundorin
Banned
 
Join Date: Feb 2014
Location: Moscow, Russia
Posts: 554
Default

This commented line in the default function was the reason of the issue:
Code:
static double charToPan(unsigned char val)
{
	double pos = ((double)val*1000.0 + 0.5) / 127.0;

	pos = (pos - 500.0) / 500.0;
	//if (fabs(pos) < 0.08) pos = 0.0;

	return pos;
}
fundorin is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.