Jump to content

Translation Mapping


HawThorn

Recommended Posts

Hello,

Before working with the mios, I want to be sure that it can do what I want. So, is it possible to program a large translation map?

I receive a CC, depend with the second value, I send a half sysex message. And with the first value, I send the other part of my sysex message.

Is it possible?

Thanks

Laurent

Link to comment
Share on other sites

Yes, a little bit more explanation:

The sysex look like: F0 7F 01 02 01 01 YY 00 XX 00 F7

So the first part of the sysex is like that: F0 7F 01 02 01 01 (3Z 3Z ) 3Z 00

And the second part of the sysex like that: (3Z 3Z) 3Z 00 F7

For YY (the second value of the control): it’s the value scale to 1-101, translate in ascii code, and put in the sysex.

Some examples:

0 ---> 1 ---> 31

19 ---> 15 ---> 31 35

60 ---> 48 ---> 34 38

107 ---> 85 ---> 38 35

127 ---> 101 ---> 31 30 31

For the XX (the first value of the CC): it’s just the value translated in an ascii code and increase by 1

Some examples for XX:

0 ---> 1 ---> 31

15 ---> 16 ---> 31 36

49 ---> 50 ---> 35 30

87 ---> 88 ---> 88 88

103 ---> 104 ---> 31 30 34

127 ---> 128 ---> 31 32 38

So for exemple if the value CC 13 120 is coming in,

the value sysex  F0 7F 01 02 01 01 39 35 00 31 34 F7

Or for the value CC 109 35, the value sysex F0 7F 01 02 01 01 32 38 00 31 31 30 00 F7

Other for the value CC 16 49, the value sysex F0 7F 01 02 01 01 33 39 00 31 37 00 F7

For the variable Y in the first part of the sysex, I can have an error of 2%.

Well, actually, I use MIDI-OX to translate my CC and to be sure I have 256 entries. 128 for the first part of the sysex and 128 for the second part.

Exemple :

*,Ctrl,*,*,0,0,Y,0,*,SysEx,F0 7F 01 02 01 01 31

*,Ctrl,*,*,28,28,Y,0,*,SysEx,F0 7F 01 02 01 01 32 32

*,Ctrl,*,*,112,112,Y,0,*,SysEx,F0 7F 01 02 01 01 38 39

*,Ctrl,4,4,*,*,N,0,*,SysEx,00 35 00 F7

*,Ctrl,34,34,*,*,N,0,*,SysEx,00 33 35 00 F7

*,Ctrl,114,114,*,*,N,0,*,SysEx,00 31 31 35 00 F7

Well, I think, I must program it like this:

If you receive the second value 00 from a CC then send 7F 01 02 01 01 31

…

if than you receive the second value 75 from a CC then send 7F 01 02 01 01 36 30

… etc

If you receive the first value 00 form a CC then send 31 00 F7

…

if than you receive the first value 101 form a CC then send 31 30 32 00 F7

… etc

And perhaps clone the CC when it coming in…

I hope I’m not too unmethodical in my explanations, if you can help me…

Link to comment
Share on other sites

Can I use a think like this? It’s not really beautiful, but...

void MIOS_MIDI_Init(void) __wparam {

if     (evnt2 == 0x00) {

// send the MIDI event F0 7F 01 02 01 31 00
  MIOS_MIDI_BeginStream();
  MIOS_MIDI_TxBufferPut(0xF0);
  MIOS_MIDI_TxBufferPut(0x7F);
  MIOS_MIDI_TxBufferPut(0x01);
  MIOS_MIDI_TxBufferPut(0x02);
  MIOS_MIDI_TxBufferPut(0x01);
  MIOS_MIDI_TxBufferPut(0x31);
  MIOS_MIDI_TxBufferPut(0x00);
  MIOS_MIDI_EndStream();
  }
//etc, etc, etc... for each my 128 values

if     (evnt1 == 0x00) {

// send the MIDI event 00 31 F7
  MIOS_MIDI_BeginStream();
  MIOS_MIDI_TxBufferPut(0x00);
  MIOS_MIDI_TxBufferPut(0x31);
  MIOS_MIDI_TxBufferPut(0xF7);
  MIOS_MIDI_EndStream();
  }
//etc, etc, etc... for each my 128 values

}

on my network I can received only CC, so it’s not important for my to do a detection of event

Link to comment
Share on other sites

It will work with MIOS, and your code is a good starting point, because it will send something - so you will be able to debug this!

However, checking for evnt2==0 is propably not correct, I'm missing the check for "evnt0==0xb0" (CC CHannel 1), etc... but I'm very sure that you will be able to complete the program by yourself once you've worked with the core module.

Just try it, get some first experiences, and once you face a problem and you are not able to solve it by yourself, ask in the forum.

Just two additional hints (beside of the missing evnt0==0xb0 check): use MIOS_MIDI_BeginStream() and MIOS_MIDI_EndStream() only once, not several times within a SysEx messages. For the beginning you could left it out, these functions are only required for the MIDIbox Link function (when several core modules are chained)

Binary->BCD conversion: if this is really required, use MIOS_HLP_Dec2BCD, it's the simplest way

Best Regards, Thorsten.

Link to comment
Share on other sites

When you are typing "make", you will see the allocated blocks after the linking phase (they are displayed be the hex2syx script). 0x7fff is the maximum on a PIC18F452. The linker will exit with an error, if this boundary is exceeded

I guess that you program currently doesn't allocate more than 2k, and by doing clever programming (e.g. use subfunctions for frequently repeated code, use data tables for a better oversight), you won't need more than 4k, so there will still be about 16k free for much more stuff

Best Regards, Thorsten.

Link to comment
Share on other sites

Hello again,

I finished the program. Well, not exactly. I do not understand perfectly how to use function which scales a value. Programming is hard for me  :'(...

I can use this :

unsigned char Scale_7bit(unsigned char evnt2, unsigned char min, unsigned char max)
{
  // scaled value is (<8-bit random> * ) >> 8
  PRODL = evnt2 << 1; // 8bit value
  PRODH = max-min+1;  // range
__asm
    movf _PRODL, W
    mulwf _PRODH, 0
__endasm;

  return min + PRODH;
}
and
  evnt2 = Scale_7bit(evnt2,
                     0x01,    
                     0x64);

but I can't understand how it's working.

I can't test actually, my PIC arrives in 2 week.

So with the minimum value 0x01 and the maximum value 0x64... If I understand, when evnt2 have a value of 0x00 it become 0x01 and for a value of 0x7F it become 0x64. Other example, for 0x55 it become 0x44. The fonction stretch the value ?

Thanks

Laurent

Link to comment
Share on other sites

Let's see if I can get this right :)

unsigned char Scale_7bit(unsigned char evnt2, unsigned char min, unsigned char max)

{

  // scaled value is (<8-bit random> * ) >> 8

  PRODL = evnt2 << 1; // 8bit value This shifts the contents of the first variable one digit to the right. This is to treat the 7 bit input as an 8 bit input. The last bit is filled in with a 0.

  PRODH = max-min+1;  // range This subtracts the minimum from the maximum to determine the range that the input value (evnt2/PRODL) can span. 

__asm      This is a marker to signal the beginning of code written in PIC ASM assembly code (Not C)

    movf _PRODL, W This moves the value in PRODL to the working register W

    mulwf _PRODH, 0 This multiplies W (the input value which has now been converted into 8 bits) with PRODH (the range between min and max) * See below for details!

__endasm; This is a marker to signal the end of code written in PIC ASM assembly code

  return min + PRODH; This adds the minimum to the PRODH (The multiple of the input and the range)

}

*From the datasheet:

MULWF Multiply W with f

Syntax: [ label ] MULWF f [,a]

Operands: 0 ? f ? 255

a ? [0,1]

Operation: (W) x (f) ? PRODH:PRODL

Status Affected: None

Encoding: 0000 001a ffff ffff

Description: An unsigned multiplication is carried

out between the contents of

W and the register file location ’f’.

The 16-bit result is stored in the

PRODH:PRODL register pair.

PRODH contains the high byte.

Both W and ’f’ are unchanged.

None of the status flags are

affected.

Note that neither overflow nor

carry is possible in this operation.

A zero result is possible but

not detected. If ‘a’ is 0, the

Access Bank will be selected,

overriding the BSR value. If

‘a’ = 1, then the bank will be

selected as per the BSR value

(default)

Link to comment
Share on other sites

  • 3 weeks later...

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...
×
×
  • Create New...