Being to support saving of instrument definitions.
This commit is contained in:
parent
83e2cc45ad
commit
c0c7f71830
59
instrument.C
59
instrument.C
|
@ -26,9 +26,25 @@
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "non.H"
|
||||||
|
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
|
/******
|
||||||
|
Instrument definition file format is thus:
|
||||||
|
|
||||||
|
"Name", n, v
|
||||||
|
|
||||||
|
Where /n/ is a note number from 0 to 127 and /v/ is a percentage of
|
||||||
|
volume.
|
||||||
|
|
||||||
|
When a system installed instrument definition is modified, the
|
||||||
|
modified version is saved in the user's $HOME. Therefore, when
|
||||||
|
loading instruments, user defined instruments always hide system
|
||||||
|
defined instruments of the same name.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
list <Instrument *> Instrument::instruments;
|
list <Instrument *> Instrument::instruments;
|
||||||
|
|
||||||
|
@ -71,13 +87,6 @@ Instrument::open ( const char *name )
|
||||||
return new Instrument ( name );
|
return new Instrument ( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
Instrument::note ( int from, int to )
|
|
||||||
{
|
|
||||||
// _map[ from ].note = to;
|
|
||||||
WARNING( "what should this do now?" );
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Instrument::note_name ( int n, char *s )
|
Instrument::note_name ( int n, char *s )
|
||||||
{
|
{
|
||||||
|
@ -97,9 +106,6 @@ Instrument::velocity ( int n, int v )
|
||||||
void
|
void
|
||||||
Instrument::translate ( midievent *e ) const
|
Instrument::translate ( midievent *e ) const
|
||||||
{
|
{
|
||||||
// int n = e->note();
|
|
||||||
|
|
||||||
// e->note( _map[ n ].note );
|
|
||||||
e->note_velocity( e->note_velocity() * _map[ e->note() ].velocity / 100 );
|
e->note_velocity( e->note_velocity() * _map[ e->note() ].velocity / 100 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +127,7 @@ Instrument::velocity ( int n ) const
|
||||||
return _map[ n ].velocity;
|
return _map[ n ].velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
bool
|
||||||
Instrument::read ( const char *s )
|
Instrument::read ( const char *s )
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
@ -161,8 +167,6 @@ Instrument::read ( const char *s )
|
||||||
|
|
||||||
DEBUG( "name: \"%s\", note: %d, velocity: %d%%", m.name, note, m.velocity );
|
DEBUG( "name: \"%s\", note: %d, velocity: %d%%", m.name, note, m.velocity );
|
||||||
|
|
||||||
// _map[ (64 + (n / 2)) - i ] = m;
|
|
||||||
|
|
||||||
_map[ note ] = m;
|
_map[ note ] = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,6 +177,35 @@ Instrument::read ( const char *s )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Instrument::write ( const char *s ) const
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
char pat[512];
|
||||||
|
|
||||||
|
sprintf( pat, "%s/%s%s.inst", config.user_config_dir, INSTRUMENT_DIR, s );
|
||||||
|
|
||||||
|
if ( ! ( fp = fopen( pat, "w" ) ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int n = 0;
|
||||||
|
for ( int i = 0; i < 127; ++i )
|
||||||
|
{
|
||||||
|
if ( _map[ i ].name )
|
||||||
|
{
|
||||||
|
fprintf( fp, "\"%s\", %d, %d\n", _map[ i ].name, i, _map[ i ].velocity );
|
||||||
|
++n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG( "wrote %d lines to instrument file \"%s\"", n, pat );
|
||||||
|
|
||||||
|
fclose( fp );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
instrument_filter ( const struct dirent *d )
|
instrument_filter ( const struct dirent *d )
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,7 +40,8 @@ class Instrument
|
||||||
struct i_map _map[128]; /* note / velocity mappings */
|
struct i_map _map[128]; /* note / velocity mappings */
|
||||||
|
|
||||||
Instrument ( const char *name );
|
Instrument ( const char *name );
|
||||||
int read ( const char *s );
|
bool read ( const char *s );
|
||||||
|
bool write ( const char *s ) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
15
main.C
15
main.C
|
@ -18,6 +18,9 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "non.H"
|
#include "non.H"
|
||||||
// #include "gui/input.H"
|
// #include "gui/input.H"
|
||||||
#include "gui/ui.H"
|
#include "gui/ui.H"
|
||||||
|
@ -27,6 +30,8 @@
|
||||||
#include "pattern.H"
|
#include "pattern.H"
|
||||||
#include "phrase.H"
|
#include "phrase.H"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Canvas *pattern_c, *phrase_c, *trigger_c;
|
Canvas *pattern_c, *phrase_c, *trigger_c;
|
||||||
|
|
||||||
sequence *playlist;
|
sequence *playlist;
|
||||||
|
@ -134,6 +139,16 @@ main ( int argc, char **argv )
|
||||||
song.random.feel = 8;
|
song.random.feel = 8;
|
||||||
song.random.probability = 0.33;
|
song.random.probability = 0.33;
|
||||||
|
|
||||||
|
asprintf( &config.user_config_dir, "%s/%s", getenv( "HOME" ), USER_CONFIG_DIR );
|
||||||
|
|
||||||
|
|
||||||
|
mkdir( config.user_config_dir, 0777 );
|
||||||
|
{
|
||||||
|
char pat[512];
|
||||||
|
snprintf( pat, 512, "%s/%s", config.user_config_dir, INSTRUMENT_DIR );
|
||||||
|
mkdir( pat, 0777 );
|
||||||
|
}
|
||||||
|
|
||||||
printf( "%s %s -- %s\n", APP_TITLE, VERSION, COPYRIGHT );
|
printf( "%s %s -- %s\n", APP_TITLE, VERSION, COPYRIGHT );
|
||||||
|
|
||||||
playlist = new sequence;
|
playlist = new sequence;
|
||||||
|
|
Loading…
Reference in New Issue