Skip to content

Commit

Permalink
added cm-32l emulation
Browse files Browse the repository at this point in the history
  • Loading branch information
mborjesson committed Jul 12, 2017
1 parent a31d801 commit c524911
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/midi.c
Expand Up @@ -25,6 +25,7 @@ static MIDI_DEVICE devices[] =
{"None", "none", NULL},
{SYSTEM_MIDI_NAME, SYSTEM_MIDI_INTERNAL_NAME, &system_midi_device},
{"Roland MT-32 Emulation", "mt32", &mt32_device},
{"Roland CM-32L Emulation", "cm32l", &cm32l_device},
{"", "", NULL}
};

Expand Down
63 changes: 52 additions & 11 deletions src/midi_mt32.c
Expand Up @@ -32,6 +32,8 @@ typedef struct mt32_t
int midi_pos;

int status_show_instruments;

char model_name[50];
} mt32_t;

void showLCDMessage(void *instance_data, const char *message)
Expand Down Expand Up @@ -80,7 +82,7 @@ static const mt32emu_report_handler_i_v0 handler_v0 = {

static const mt32emu_report_handler_i handler = { &handler_v0 };

static int roms_present = -1;
static int roms_present[] = { -1, -1 };

mt32emu_return_code mt32_check(const char* func, mt32emu_return_code ret, mt32emu_return_code expected)
{
Expand All @@ -94,9 +96,16 @@ mt32emu_return_code mt32_check(const char* func, mt32emu_return_code ret, mt32em

int mt32_available()
{
if (roms_present < 0)
roms_present = (rom_present("mt32/mt32_control.rom") && rom_present("mt32/mt32_pcm.rom"));
return roms_present;
if (roms_present[0] < 0)
roms_present[0] = (rom_present("mt32/mt32_control.rom") && rom_present("mt32/mt32_pcm.rom"));
return roms_present[0];
}

int cm32l_available()
{
if (roms_present[1] < 0)
roms_present[1] = (rom_present("cm32l/cm32l_control.rom") && rom_present("cm32l/cm32l_pcm.rom"));
return roms_present[1];
}

void mt32_stream(mt32emu_context context, int16_t* stream, int len)
Expand Down Expand Up @@ -142,17 +151,17 @@ void mt32_sysex(midi_device_t* device, uint8_t* data, unsigned int len)
if (context) mt32_check("mt32emu_play_sysex", mt32emu_play_sysex(context, data, len), MT32EMU_RC_OK);
}

void* mt32_init()
static void* mt32emu_init(char* control_rom, char* pcm_rom)
{
char s[512];

mt32_t* data = malloc(sizeof(mt32_t));
memset(data, 0, sizeof(mt32_t));
mt32emu_context context = mt32emu_create_context(handler, data);
if (
!rom_getfile("mt32/mt32_control.rom", s, 512) ||
!rom_getfile(control_rom, s, 512) ||
!mt32_check("mt32emu_add_rom_file", mt32emu_add_rom_file(context, s), MT32EMU_RC_ADDED_CONTROL_ROM) ||
!rom_getfile("mt32/mt32_pcm.rom", s, 512) ||
!rom_getfile(pcm_rom, s, 512) ||
!mt32_check("mt32emu_add_rom_file", mt32emu_add_rom_file(context, s), MT32EMU_RC_ADDED_PCM_ROM) ||
!mt32_check("mt32emu_open_synth", mt32emu_open_synth(context), MT32EMU_RC_OK))
{
Expand Down Expand Up @@ -197,6 +206,22 @@ void* mt32_init()
return dev;
}

void* mt32_init()
{
midi_device_t* dev = mt32emu_init("mt32/mt32_control.rom", "mt32/mt32_pcm.rom");
if (dev)
strcpy(((mt32_t*)dev->data)->model_name, "MT-32");
return dev;
}

void* cm32l_init()
{
midi_device_t* dev = mt32emu_init("cm32l/cm32l_control.rom", "cm32l/cm32l_pcm.rom");
if (dev)
strcpy(((mt32_t*)dev->data)->model_name, "CM-32L");
return dev;
}

void mt32_close(void* p)
{
if (!p) return;
Expand Down Expand Up @@ -239,27 +264,30 @@ void mt32_add_status_info(char *s, int max_len, void *p)
// snprintf(s, max_len, "MT-32 Partial count: %d\n", part_count);
if (strlen(data->message))
{
sprintf(temps, "MT-32 message: %s\n", data->message);
sprintf(temps, "%s message: %s\n", data->model_name, data->message);
strncat(s, temps, max_len);
}
if (mt32emu_is_active(context))
{
sprintf(temps, "MT-32 playback frequency: %iHz\n", data->samplerate);
sprintf(temps, "%s playback frequency: %iHz\n", data->model_name, data->samplerate);
strncat(s, temps, max_len);
if (data->status_show_instruments)
{
for (i = 0; i < 8; ++i)
{
const char* patch_name = mt32emu_get_patch_name(context, i);
// mt32emu_get_playing_notes(context, i, &keys, &velocities);
sprintf(temps, "MT-32 inst. %d: %s\n", i+1, patch_name);
sprintf(temps, "%s inst. %d: %s\n", data->model_name, i+1, patch_name);
strncat(s, temps, max_len);
}
}
strncat(s, "\n", max_len);
}
else
strncat(s, "MT-32 playback stopped\n\n", max_len);
{
strncat(s, data->model_name, max_len);
strncat(s, " playback stopped\n\n", max_len);
}
}

static device_config_t mt32_config[] =
Expand Down Expand Up @@ -363,3 +391,16 @@ device_t mt32_device =
mt32_add_status_info,
mt32_config
};

device_t cm32l_device =
{
"Roland CM-32L Emulation",
0,
cm32l_init,
mt32_close,
cm32l_available,
NULL,
NULL,
mt32_add_status_info,
mt32_config
};
1 change: 1 addition & 0 deletions src/midi_mt32.h
@@ -1 +1,2 @@
extern device_t mt32_device;
extern device_t cm32l_device;

0 comments on commit c524911

Please sign in to comment.