@@ -113,11 +113,17 @@ Instrument::velocity ( int n, int v ) | |||||
_dirty = true; | _dirty = true; | ||||
} | } | ||||
/* Should only be passed NOTE ON/OFF events! */ | |||||
void | |||||
/** Translate event, should only be passed NOTE ON/OFF events, returns | |||||
true if note is valid for this mapping */ | |||||
bool | |||||
Instrument::translate ( midievent *e ) const | Instrument::translate ( midievent *e ) const | ||||
{ | { | ||||
if ( ! note_name( e->note() ) ) | |||||
return false; | |||||
e->note_velocity( e->note_velocity() * _map[ e->note() ].velocity / 100 ); | e->note_velocity( e->note_velocity() * _map[ e->note() ].velocity / 100 ); | ||||
return true; | |||||
} | } | ||||
const char * | const char * | ||||
@@ -55,7 +55,7 @@ public: | |||||
void note_name ( int n, char *s ); | void note_name ( int n, char *s ); | ||||
/* inspection */ | /* inspection */ | ||||
void translate ( midievent *e ) const; | |||||
bool translate ( midievent *e ) const; | |||||
const char * note_name ( int n ) const; | const char * note_name ( int n ) const; | ||||
int height ( void ) const; | int height ( void ) const; | ||||
const char * name ( void ) const; | const char * name ( void ) const; | ||||
@@ -101,7 +101,7 @@ Mapping::key ( void ) const | |||||
return _type == INSTRUMENT ? -1 : _key; | return _type == INSTRUMENT ? -1 : _key; | ||||
} | } | ||||
void | |||||
bool | |||||
Mapping::translate ( midievent *e ) const | Mapping::translate ( midievent *e ) const | ||||
{ | { | ||||
switch ( _type ) | switch ( _type ) | ||||
@@ -111,6 +111,8 @@ Mapping::translate ( midievent *e ) const | |||||
case SCALE: | case SCALE: | ||||
return _scale->translate( _key, e ); | return _scale->translate( _key, e ); | ||||
} | } | ||||
return false; | |||||
} | } | ||||
int | int | ||||
@@ -64,7 +64,7 @@ public: | |||||
void key ( int n ); | void key ( int n ); | ||||
/* inspection */ | /* inspection */ | ||||
void translate ( midievent *e ) const; | |||||
bool translate ( midievent *e ) const; | |||||
const char * note_name ( int n ) const; | const char * note_name ( int n ) const; | ||||
int velocity ( int n ) const; | int velocity ( int n ) const; | ||||
int key ( void ) const; | int key ( void ) const; | ||||
@@ -454,12 +454,13 @@ try_again: | |||||
if ( me.is_note_on() ) | if ( me.is_note_on() ) | ||||
{ | { | ||||
mapping.translate( &me ); | |||||
midi_output_event( _port, &me, 1 + e->note_duration() ); | |||||
if ( mapping.translate( &me ) ) | |||||
midi_output_event( _port, &me, 1 + e->note_duration() ); | |||||
} | } | ||||
else | else | ||||
if ( me.is_note_off() ) | if ( me.is_note_off() ) | ||||
midi_output_event( _port, &me, 0 ); | |||||
if ( mapping.translate( &me ) ) | |||||
midi_output_event( _port, &me, 0 ); | |||||
else | else | ||||
/* any other event type */ | /* any other event type */ | ||||
midi_output_event( _port, &me ); | midi_output_event( _port, &me ); | ||||
@@ -176,11 +176,13 @@ Scale::_degree ( int k, int n ) const | |||||
} | } | ||||
/* translate NOTE event. Behavior is undefined for other event types */ | /* translate NOTE event. Behavior is undefined for other event types */ | ||||
void | |||||
bool | |||||
Scale::translate ( int k, midievent *e ) const | Scale::translate ( int k, midievent *e ) const | ||||
{ | { | ||||
/* does nothing now... */ | |||||
/* TODO: invalidate events that are note on/offs for notes outside the scale. */ | |||||
if ( ! note_name( k, e->note() ) ) | |||||
return false; | |||||
else | |||||
return true; | |||||
} | } | ||||
const char * | const char * | ||||
@@ -41,7 +41,7 @@ public: | |||||
static const char * chromatic_name ( int n ); | static const char * chromatic_name ( int n ); | ||||
static int octave ( int n ); | static int octave ( int n ); | ||||
void translate ( int k, midievent *e ) const; | |||||
bool translate ( int k, midievent *e ) const; | |||||
int note ( int k, int n ) const; | int note ( int k, int n ) const; | ||||
const char * note_name ( int k, int n ) const; | const char * note_name ( int k, int n ) const; | ||||
const char * name ( void ) const; | const char * name ( void ) const; | ||||