Jump to content

Mios32 midi_package.chn == 9 reacts at MidiChannel 10 (offset of -1) -LPC17


Phatline
 Share

Recommended Posts

Tutorial 2 - Parsing Midi:

When my sequencer is sending out a note on Midichannel 10, then my synthesizer reacts @ Channel 10, but MIOS and LPC17 sys "I got it on Midichannel 9"

 

I just took the Tutorial below, and changed only - to display the mididata, else i dont changed things (no change in config or header files)

 

Code:

// $Id: app.c 1919 2014-01-08 19:13:48Z tk $
//MIOS32 Tutorial #002: Parsing MIDI
#include <mios32.h>
#include "app.h"
void APP_Init(void){MIOS32_BOARD_LED_Init(0xffffffff);}
void APP_Background(void){}
void APP_Tick(void){}
void APP_MIDI_Tick(void){}
void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package){
u8 ab = 0;
  // 1) the LED should be turned on whenever a Note On Event with velocity > 0
  // has been received
if( port == 32){
if( midi_package.chn == 9){
if( midi_package.type == NoteOn && midi_package.velocity > 0 ) {
MIOS32_BOARD_LED_Set(0x0001, 1);
ab=1;}

  // 2) the LED should be turned off whenever a Note Off Event or a Note On
  // event with velocity == 0 has been received (the MIDI spec says, that velocity 0
  // should be handled like Note Off)
if( (midi_package.type == NoteOff) || (midi_package.type == NoteOn && midi_package.velocity == 0) ){
MIOS32_BOARD_LED_Set(0x0001, 0);
ab=0;}

MIOS32_LCD_Clear();         // clear screen
MIOS32_LCD_CursorSet(0, 0); // X,Y 
MIOS32_LCD_PrintFormattedString("%d %d %d %d",ab, port, midi_package.note, midi_package.chn);
}//End Midi CHN 11
}//End Port
}//End Hook

void APP_SRIO_ServicePrepare(void){}
void APP_SRIO_ServiceFinish(void){}
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value){}
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer){}
void APP_AIN_NotifyChange(u32 pin, u32 pin_value){}

 

is there a offset to set?

Link to comment
Share on other sites

MIDI Channels are counted from 0

 

If you don't like this, you could use the mios32_midi_chn_t based enums (which are defined in mios32_midi.h) in your code.

They are available by default, just try it out:

 

replace

if( midi_package.chn == 9){

by:

if( midi_package.chn == Chn10){

Best Regards, Thorsten.

Link to comment
Share on other sites

Search for mios32_midi_chn_t in this file

(CTRL+F, then enter this keyword into the search mask of your web browser)

 

Again: this file is included by default (via mios.h), you can just use the enum as shown in my example.

 

Btw.: you don't need to copy&paste such code into the posting, please reference it with the SVN link: http://svnmios.midibox.org/filedetails.php?repname=svn.mios32&path=%2Ftrunk%2Finclude%2Fmios32%2Fmios32_midi.h

 

Best Regards, Thorsten.

Link to comment
Share on other sites

hmm i deletet the code... still dont found it

 

there is no text like " midi_package.chn"

 

the only CHN things are:

typedef enum {
  Chn1,
  Chn2,
  Chn3,
  Chn4,
  Chn5,
  Chn6,
  Chn7,
  Chn8,
  Chn9,
  Chn10,
  Chn11,
  Chn12,
  Chn13,
  Chn14,
  Chn15,
  Chn16
} mios32_midi_chn_t;


typedef union {
  struct {
    u32 ALL;
  };
  struct {
    u8 cin_cable;
    u8 evnt0;
    u8 evnt1;
    u8 evnt2;
  };
  struct {
    u8 type:4;
    u8 cable:4;
    u8 chn:4; // mios32_midi_chn_t
    u8 event:4; // mios32_midi_event_t
    u8 value1;
    u8 value2;
  };

  // C++ doesn't allow to redefine names in anonymous unions
  // as a simple workaround, we rename these redundant names
  struct {
    u8 cin:4;
    u8 dummy1_cable:4;
    u8 dummy1_chn:4; // mios32_midi_chn_t
    u8 dummy1_event:4; // mios32_midi_event_t
    u8 note:8;
    u8 velocity:8;
  };
  struct {
    u8 dummy2_cin:4;
    u8 dummy2_cable:4;
    u8 dummy2_chn:4; // mios32_midi_chn_t
    u8 dummy2_event:4; // mios32_midi_event_t
    u8 cc_number:8;
    u8 value:8;
  };
  struct {
    u8 dummy3_cin:4;
    u8 dummy3_cable:4;
    u8 dummy3_chn:4; // mios32_midi_chn_t
    u8 dummy3_event:4; // mios32_midi_event_t
    u8 program_change:8;
    u8 dummy3:8;
  };
} mios32_midi_package_t;

forgive me i am a newbe, shoul i change CHN:4 to CHN5?

Edited by Phatline
Link to comment
Share on other sites

You shouldn't change anything in the mios32_midi.h file!

And please never start such modifications outside your own application to prevent a big disaster ;-)

 

The "midi_package.chn == 9" is part of your own code.

I'm surprised that you can't find it there - just search this keyword in your initial posting.

It's even part of the subject.

 

I proposed that you replace the 9 by Chn10 to improve the readability, nothing else.

 

Just try it out - it works! :smile:

 

Best Regards, Thorsten.

 

P.S.: I will avoid to give you background informations in future, they confuse you too much.

 
Link to comment
Share on other sites

i still thougt it will be not good to change something in mios (i understand, that a nother me with a nother laptopt and a nother Mios - in the near future - will run against walls, because the program is not working as it should )

 

ok got it, just write Chn10 instead of 9

 

@confuse: got a new vocable:

ENUM  :santa: 

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...