Actually mute notes outside of current mapping.

This commit is contained in:
Jonathan Moore Liles 2008-02-13 13:42:00 -06:00
parent 9bebbffd46
commit 742679c5ad
7 changed files with 23 additions and 12 deletions

View File

@ -113,11 +113,17 @@ Instrument::velocity ( int n, int v )
_dirty = true; _dirty = true;
} }
/* Should only be passed NOTE ON/OFF events! */ /** Translate event, should only be passed NOTE ON/OFF events, returns
void 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 *

View File

@ -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;

View File

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

View File

@ -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;

View File

@ -454,11 +454,12 @@ try_again:
if ( me.is_note_on() ) if ( me.is_note_on() )
{ {
mapping.translate( &me ); if ( mapping.translate( &me ) )
midi_output_event( _port, &me, 1 + e->note_duration() ); midi_output_event( _port, &me, 1 + e->note_duration() );
} }
else else
if ( me.is_note_off() ) if ( me.is_note_off() )
if ( mapping.translate( &me ) )
midi_output_event( _port, &me, 0 ); midi_output_event( _port, &me, 0 );
else else
/* any other event type */ /* any other event type */

View File

@ -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... */ if ( ! note_name( k, e->note() ) )
/* TODO: invalidate events that are note on/offs for notes outside the scale. */ return false;
else
return true;
} }
const char * const char *

View File

@ -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;