How to make the volume ramp with calculation.

espen.sandorfespen.sandorf Registered UserPosts: 29
Hi all..

I have a Mixer / volume control which i want to use to change the volume. the problem is that it needs a string where the last to digits represents the ascii of the numbers 0 - 255. How can i make this ramp using calculation. i've added the code i'm trying to use. and a cutout from the manual of the mixer.

Thanks in advance.


Sent to Unit
!04SR01XX<CR>

Set Source Volume

XX = Volume setting ranging from 00 – FF with FF being volume control at
full and 00 being minimum volume. The 256 volume steps are internally
scaled in the IN600 from the 65 available volume steps.

Received from Unit

*01SR01XX<CR>

Source volume value

XX = Volume setting ranging from 00 – FF with FF being volume control at
full and 00 being minimum volume. The 256 volume steps are internally
scaled in the IN600 from the 65 available volume steps.
See note below for more information on volume scaling



BUTTON_EVENT[dvTP,cVolButs]//998=VOL NED, 999=VOL OPP
{
    hold[1,repeat]:
    {
	SWITCH(BUTTON.INPUT.CHANNEL)
	{
	    CASE 999:	SEND_STRING dvMixer,"'!04SR01'(nVolume+01),$0D"
	    CASE 998:	SEND_STRING dvMixer,"'!04SR01'(nVolume-01),$0D"
	}
    }
}


DATA_EVENT[dvMixer]
{
    STRING:
    {
	SELECT
	{	
	    ACTIVE(FIND_STRING(DATA.TEXT,'*01SR01',1)):
	    {
		nVolume = Right_String(DATA.TEXT,2)
		SEND_LEVEL dvTP,5,nVolume
		SEND_COMMAND dvTP,"'^TXT-5,0,',ITOA((nVolume*100)/255),'%'"
	    }
	}	 
    }
}

Comments

  • espen.sandorfespen.sandorf Registered User Posts: 29
    I've been reading post around the forum and changed the code a bit?

    BUTTON_EVENT[dvTP,cVolButs]//998=VOL NED, 999=VOL OPP
    {
        hold[1,repeat]:
        {
    	SWITCH(BUTTON.INPUT.CHANNEL)
    	{
    	    CASE 999:	SEND_STRING dvMixer,"'!04SR01',ITOA(nVolume+01),' ',$0D"
    	    CASE 998:	SEND_STRING dvMixer,"'!04SR01',ITOA(nVolume-01),' ',$0D"
    	}
        }
    }
    
  • jweatherjweather Junior Member Posts: 320
    To turn 255 into FF, you're looking for itohex(). You will also need to change nVolume each time, otherwise the volume will never change more than one step, assuming nVolume isn't getting set by feedback from the switcher:
    BUTTON_EVENT[dvTP,cVolButs]//998=VOL NED, 999=VOL OPP
    {
        hold[1,repeat]:
        {
    	SWITCH(BUTTON.INPUT.CHANNEL)
    	{
    	    CASE 999:	{
    	    	    nVolume++
    	    	    SEND_STRING dvMixer,"'!04SR01',ITOHEX(nVolume),' ',$0D"
    	    }
    	    CASE 998:	{
    	    	    nVolume--
    	    	    SEND_STRING dvMixer,"'!04SR01',ITOHEX(nVolume),' ',$0D"
    	    }
    	}
        }
    }
    

    Might want to add some more logic to keep the volume from wrapping around (over 255 or under 0, which would underflow into 65535)
  • Spire_JeffSpire_Jeff Formerly Caffeinated Programmer Posts: 1,917
    Try this:
    BUTTON_EVENT[dvTP,cVolButs]//998=VOL NED, 999=VOL OPP
    {
        hold[1,repeat]:
        {
    	SWITCH(BUTTON.INPUT.CHANNEL)
    	{
    	    CASE 999:{
    			nVolume++
    			SEND_STRING dvMixer,"'!04SR01',itohex(nVolume),$0D"
    		}
    	    CASE 998:{
    			nVolume--
    			SEND_STRING dvMixer,"'!04SR01',itohex(nVolume),$0D"
    		}
    
    	}
        }
    }
    
    
    DATA_EVENT[dvMixer]
    {
        STRING:
        {
            stack_var char sIncMsg[50]
            while(find_string(data.text,"$0D",1){
    		sIncMsg = remove_string(data.text,"$0D",1);
    		SELECT
    		{	
    		    ACTIVE(FIND_STRING(sIncMsg,'*01SR01',1)):
    	    	    {
    			remove_string(sIncMsg,'*01SR01',1);
    			nVolume = hextoi(sIncMsg);
    			SEND_LEVEL dvTP,5,nVolume
    			SEND_COMMAND dvTP,"'^TXT-5,0,',ITOA((nVolume*100)/255),'%'"
    		    }	
    		}	 
    	}
        }
    }
    
    [/QUOTE]

    I think that will do what you need. For the raise/lower buttons, you were not saving the value changes to the volume, so the volume would never change. You might also want to consider moving more than a value of 1 each time. If you are happy with the ramp speed, you could just change to nVolume = nVolume +/- 5 and increase the hold time to 5. This will reduce traffic considerably and I doubt you will notice the difference audibly.

    I also changed the incoming string handler a little. First, you were not accounting for the <CR> at the end of the string, so you were only grabbing the last hex digit in the volume, not both of them. Second, I would recommend using CREATE_BUFFER and parsing the buffer on a string event. The code provided can easily be changed to work on a buffer variable. This will handle messages that are split by the processor into two or more string events.

    Jeff
  • espen.sandorfespen.sandorf Registered User Posts: 29
    I'll just delete that reply since it got outdated by a new respons.

    The button event looks good and i understand what it's doing. But i will have a problem with the data_event if it does not work. cause i have no idea what it actually does. i'm not to experienced so i'm trying to keep the code simple so i can modifie it myself if needed. Would the previos data_event work.

    Thank you very much for your help.
  • espen.sandorfespen.sandorf Registered User Posts: 29
    I think maybe i understand it afterall. I just had to sink in the information first.

    Thanks
  • Spire_JeffSpire_Jeff Formerly Caffeinated Programmer Posts: 1,917
    Post here if you have problems getting the volume to display correctly. The code I posted will handle two messages sent in one string event, but it will not handle a message that is split between two string events.

    Jeff
  • espen.sandorfespen.sandorf Registered User Posts: 29
    Thank you very much, tested the code first time today, and it worked. Only problem wich probably isn't a problem is that the string ramps beyond what the mixer understands and i have to wait to get back to a decimal it understands before it starts ramping back up or down depending on which way i went.

    I guess no one will go to max or min so its really no big deal.

    espen
  • jjamesjjames AMX Sustaining Engineer Posts: 2,898
    Don't forget that when using itohex(), 0-15 will only return one one character, ex: decimal 13 return "D", not "0D", so if your device is looking for a hex value two characters long, you'll have to do some formatting. Basically, you can format it like so:

    s_theHexValue = right_string("'0',itohex(i_theDecValue)",2);

    This will make sure it's always padded by a zero when needed.
  • Joe HebertJoe Hebert Junior Member Posts: 2,154
    jjames wrote: »
    s_theHexValue = right_string("'0',itohex(i_theDecValue)",2);

    This will make sure it's always padded by a zero when needed.
    As will this:
    s_theHexValue = format('%02X',i_theDecValue)
  • espen.sandorfespen.sandorf Registered User Posts: 29
    jjames wrote: »
    Don't forget that when using itohex(), 0-15 will only return one one character, ex: decimal 13 return "D", not "0D", so if your device is looking for a hex value two characters long, you'll have to do some formatting. Basically, you can format it like so:

    s_theHexValue = right_string("'0',itohex(i_theDecValue)",2);

    This will make sure it's always padded by a zero when needed.


    Thats probably why the feedback stops at 6 percent, where in this code will i do the formatting?
    DATA_EVENT[dvMixer]
    {
        STRING:
        {
            stack_var char sIncMsg[50]
            while(find_string(data.text,"$0D",1))
    	{
    	    sIncMsg = remove_string(data.text,"$0D",1);
    	    SELECT
    	    {	
    		ACTIVE(FIND_STRING(sIncMsg,'*01SR01',1)):
    		{
    		    remove_string(sIncMsg,'*01SR01',1);
    		    nVolume = hextoi(sIncMsg);
    		    SEND_LEVEL dvTP,5,nVolume
    		    SEND_COMMAND dvTP,"'^TXT-5,0,',ITOA((nVolume*100)/254),'%'"
    		}	
    	    }	 
    	}
        }
    }
    
    
  • jjamesjjames AMX Sustaining Engineer Posts: 2,898
    Well - first, make sure the device is not responding to the single hex value, for example '!04SR01D' instead of '!04SR010D'; if it's not responding to the former - then you'l definitely need to format it when it's sent: so in Jeff's example, it'd be here -
    SEND_STRING dvMixer,"'!04SR01',right_string("'0',itohex(nVolume)",2),$0D"
    

    Joe - I *ALWAYS* forget about the FORMAT command, probably because the documentation is poor in my opinion, and needs more examples with what you could do with it. It confuses the heck out of me, so I just do stuff like I posted. :-)
Sign In or Register to comment.