Jump to content

NRPN->CC


js
 Share

Recommended Posts

uhh, Nice with some examples this makes it much easier to start making some code.

One of the examples shows how to convert from CC to NRPN. How difficult difficult would it be to do the same from NRPN to CC? I´ve have some programming experience (mostly java, C# and a bit C & C++) from my education a few years ago but havn´t programmed anything the last couple of years.

Thanks alot for this site and wonderful toys! (love my sidx3, going to be sidx4 soon :) )

Jesper from Denmark

Link to comment
Share on other sites

Thaks alot for this new example!! :D

I´ve got some more things im not sure of, but I think that I have to try it out for myself and i´ll probaly figure it out somehow...

First I need the hardware. I think that i´ll reuse my old midi merger and make at stripped down core by changing the pic and xtal (guess it should work (made a few minimal breadboard cores before :) )

Also going to find some more reading material on midi. Got a book on midi and c++, but I don´t know how much it´s got on Nrpns

If I make something usefull im going to post the code here.

Thanks again for caring and making the examples :)

Jesper 

Just and update:

Tried to insert the code at run the make.bat and succes!! Now I just need the hardware.. Only problem on the way was that emacs wouldnt run (emacs.exe have experienced an error and the program has shut down....)

going to try ultra edit (like to have some colors on the code :) )

Link to comment
Share on other sites

I´ve actually tried it out and some of it to work. I had to bypass some of the code though...  ::)

I need it to listen to midi channel 16 and I managed to change it the first placein the code but i havn´t figured out how to do it in the if-sentence:

  case 0xb0: // CC: 3 bytes

// only listen on first MIDI channel

if( evnt0 == 0xb0 ) {

  switch( evnt1 ) {

      case 0x63: // NRPN MSB

//more code :)

another thing is that i need to make the converter store values for some CC´s Now the value is either 1 or 127 for an encoder, would like it to remember the values for the different encoders. Think im going to try a unsigned char for this..

I might also think that i need to assign the input nrpn´s to specifik CC cause it seems like some of them are not beeing converted properly. In mios studio they show up as CC Undefined value.

Anyhow, this is great progress for me. Makes me way more positive about makin this converter thingy. Just a shame that I had to borrow a core from my sid to get started....

Jesper

Link to comment
Share on other sites

Hi Jesper,

In the "if" just check for 0xbf (which stands for CC, Channel 16)

Don't write "case 0xb0", because this is a check for a masked value (evnt0 & 0xf0), the lower nibble is always 0

another thing is that i need to make the converter store values for some CC´s Now the value is either 1 or 127 for an encoder, would like it to remember the values for the different encoders. Think im going to try a unsigned char for this..

yes, you can store it in an array of "unsigned char"

I might also think that i need to assign the input nrpn´s to specifik CC cause it seems like some of them are not beeing converted properly. In mios studio they show up as CC Undefined value.

Which text is displayed by MIDI-Ox?

Best Regards, Thorsten.

Link to comment
Share on other sites

Have made some great progress today, manage to make 8encoders work with absolute values and recive thier cc value from the host. The code is not pretty and there are some problemes. For eksample does the cc value only go to 126 caues of the funktion i made to speed it up a bit.

The encoder that doesn´t respond in ableton is CC123 (all note off) guess that it might be ableton that dont allow the use of this CC cause it looks fine in midiox. Going to try to remap this encoder.

another thing to do is to make the buttons send 127 when they are pressed instread of when they are released but that should be pretty easy I guess. I also see some potential trouble when i get to the encoders wich output CC 98 and 99. But ill probaly find a solution for that as well, possible a remapto other cc´s

I repeat a lot of the code,but havn´t figured out how to avoid that  ::)

Here the code for today:

unsigned char setCCvalue(
  unsigned char nrpn_value_msb, unsigned char ccValue){
  	//calc the CC values, note:only goes to 126 :/
  	    		switch (nrpn_value_msb ){
  	    			case 0x00:
  	  					if (ccValue < 0x7e){
  	    				ccValue++;
  	    				ccValue++;
  	    			break;
  	    				} else{	break; }
  	    	
  	    		case	0x7f:  	    	
  	    			if (ccValue > 0x01){
  	    			ccValue--;
  	    			ccValue--;
  	    		break;
  	    			} else{ break;	}
  	    	}
  	    		return ccValue;
  	    	
}
/////////////////////////////////////////////////////////////////////////////
//  This function is called by MIOS when a complete MIDI event has been received
/////////////////////////////////////////////////////////////////////////////
void MPROC_NotifyReceivedEvnt(unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam
{
// static variables don't "forget" their values when the function
  // is called again - we are using them to store the NRPN address/data
  static unsigned char nrpn_msb;
  static unsigned char nrpn_lsb;
  static unsigned char nrpn_value_msb;
  static unsigned char nrpn_value_lsb;
  
 //static unsigned char ccValue;
 // static unsigned char ccValue2;

  static unsigned char ccValue[18]; //holds value of the 18 encoders

  // check MIDI channel, it should be 0 (-> channel #1)
  if( (evnt0 & 0x0f) == 15 ) {

    switch( evnt0 & 0xf0 ) {
      case 0x80: // Note-Off: 3 bytes
      case 0x90: // Note-On: 3 bytes
      case 0xa0: // Aftertouch: 3 bytes
      case 0xe0: // Pitchbend: 3 bytes
        MIOS_MIDI_TxBufferPut(evnt0);
        MIOS_MIDI_TxBufferPut(evnt1);
        MIOS_MIDI_TxBufferPut(evnt2);
        break;
      case 0xc0: // Program Change: 2 bytes
      case 0xd0: // Poly Aftertouch: 2 bytes
        MIOS_MIDI_TxBufferPut(evnt0);
        MIOS_MIDI_TxBufferPut(evnt1);
        break;

      case 0xb0: // CC: 3 bytes
	// only listen on first MIDI channel
	if( evnt0 == 0xbf ) {
	  switch( evnt1 ) {
				//STORE DATA FROM HOST:
				case 0x74:
				ccValue[0] = evnt2;
				break;	

				case 0x75:
				ccValue[1] = evnt2;
				break;

				case 0x76:
				ccValue[2] = evnt2;
				break;	

				case 0x77:
				ccValue[3] = evnt2;
				break;
				case 0x78:
				ccValue[4] = evnt2;
				break;	

				case 0x79:
				ccValue[5] = evnt2;
				break;
				case 0x7a:
				ccValue[6] = evnt2;
				break;	

				case 0x7b:
				ccValue[7] = evnt2;
				break;

					case 0x14:
				ccValue[8] = evnt2;
				break;

	  	
	  	
	  	// get the nrpn´s
  	    case 0x63: // NRPN MSB
	      nrpn_msb = evnt2; // store it
	      break;
  	    case 0x62: // NRPN LSB
	      nrpn_lsb = evnt2; // store it
	      break;
  	    case 0x26: // NRPN Value LSB
	      nrpn_value_lsb = evnt2; // store it
	      break;
  	    case 0x06: // NRPN Value MSB
  	  	nrpn_value_msb = evnt2; // store it...
  	 
  	 //set the cc values
  	if (nrpn_lsb == 0x74) {   
				ccValue[0] = setCCvalue(nrpn_value_msb,ccValue[0]);
				nrpn_value_msb = ccValue[0];
			}

			else if (nrpn_lsb == 0x75){
				ccValue[1] = setCCvalue(nrpn_value_msb,ccValue[1]);
				nrpn_value_msb = ccValue[1];
			}
			else if (nrpn_lsb == 0x76){
				ccValue[2] = setCCvalue(nrpn_value_msb,ccValue[2]);
				nrpn_value_msb = ccValue[2];
			}else if (nrpn_lsb == 0x77){
				ccValue[3] = setCCvalue(nrpn_value_msb,ccValue[3]);
				nrpn_value_msb = ccValue[3];
			}else if (nrpn_lsb == 0x78){
				ccValue[4] = setCCvalue(nrpn_value_msb,ccValue[4]);
				nrpn_value_msb = ccValue[4];
			}else if (nrpn_lsb == 0x79){
				ccValue[5] = setCCvalue(nrpn_value_msb,ccValue[5]);
				nrpn_value_msb = ccValue[5];
			}else if (nrpn_lsb == 0x7a){
				ccValue[6] = setCCvalue(nrpn_value_msb,ccValue[6]);
				nrpn_value_msb = ccValue[6];
			}else if (nrpn_lsb == 0x7b){
				ccValue[7] = setCCvalue(nrpn_value_msb,ccValue[7]);
				nrpn_value_msb = ccValue[7];
			}else if (nrpn_lsb == 0x14){
				ccValue[8] = setCCvalue(nrpn_value_msb,ccValue[8]);
				nrpn_value_msb = ccValue[8];
			}else {	nrpn_value_msb = evnt2;    	}
	      


	      // ...and forward CC
	      MIOS_MIDI_TxBufferPut(evnt0);
	      MIOS_MIDI_TxBufferPut(nrpn_lsb); // could also be mapped
	      MIOS_MIDI_TxBufferPut(nrpn_value_msb);
	      break;
  	    default:
	      // all other CCs are ignored
	}
	} else {
	 //  CCs on all other channels are forwarded directly
          MIOS_MIDI_TxBufferPut(evnt0);
          MIOS_MIDI_TxBufferPut(evnt1);
          MIOS_MIDI_TxBufferPut(evnt2);
        
	}

      default:
        // note: status messages (>= 0xf0) must be handled within MPROC_NotifyReceivedByte)
        break;
     }
  }
}

Going to post my progress as I continue.

Btw I started using mios studio instead of midiox and i must say that it a wonderfull tool, it make the code upload much easier :)

Also it´s nice to have the C examples, I fell very inspirred to make my own code :D

bye and goodnight

Jesper

Link to comment
Share on other sites

Hi Jesper,

this:


  if (ccValue < 0x7e){
      ccValue++;
      ccValue++;
      break;
      } else{ break; }
[/code] can be simplified as:
[code]
  ccValue += 2;
  if( ccValue >= 128 )
    ccValue = 127;
and decrements with:

  ccValue -= 2;
  if( ccValue >= 128 )
    ccValue = 0;
[/code]

Checking for ccValue >= 128 is not an error - ccValue is an "unsigned char" (an 8bit value), which means, once there is an underrun, the resulting value will be <= 255

Best Regards, Thorsten.

Link to comment
Share on other sites

Thanks for the input, made the changes and the compiled fine. Havn´t tried the yet though.. Spend the last few days building a new core but somehow i´ve messed it up. Can´t seem to fine the error, when I mesure on it the voltages seems fine but when I plug in a pic sends some strange messages. If I try the afterwards in another (working) core it sends the same messages. Seems like my new core deletes some of the bootloader :-\  Not giving up though... i´ll keep trying! ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...