static void _mp_draw(void) { const char *name = NULL; int n, i; if (_mp_text[0] == '!') { /* inst */ n = instrument_get_current(); if (n) name = song_get_instrument(n)->name; else name = "(No Instrument)"; } else if (_mp_text[0] == '@') { /* samp */ n = sample_get_current(); if (n > 0) name = song_get_sample(n)->name; else name = "(No Sample)"; } else { name = _mp_text; } i = strlen(name); draw_fill_chars(_mp_text_x, _mp_text_y, _mp_text_x + 17, _mp_text_y, 2); draw_text_len( name, 17, _mp_text_x, _mp_text_y, 0, 2); if (i < 17 && name == _mp_text) { draw_char(':', _mp_text_x + i, _mp_text_y, 0, 2); } draw_box(_mp_text_x, _mp_text_y + 1, _mp_text_x + 14, _mp_text_y + 3, BOX_THIN | BOX_INNER | BOX_INSET); }
void draw_note_13(int x, int y, const song_note_t *note, int cursor_pos, int fg, int bg) { int cursor_pos_map[9] = { 0, 2, 4, 5, 7, 8, 10, 11, 12 }; char note_text[16], note_buf[4], vol_buf[4]; char instbuf[4]; get_note_string(note->note, note_buf); get_volume_string(note->volparam, note->voleffect, vol_buf); /* come to think of it, maybe the instrument text should be * created the same way as the volume. */ if (note->instrument) num99tostr(note->instrument, instbuf); else strcpy(instbuf, "\xad\xad"); snprintf(note_text, 16, "%s %s %s %c%02X", note_buf, instbuf, vol_buf, get_effect_char(note->effect), note->param); if (show_default_volumes && note->voleffect == VOLFX_NONE && note->instrument > 0 && NOTE_IS_NOTE(note->note)) { song_sample_t *smp = song_is_instrument_mode() ? csf_translate_keyboard(current_song, song_get_instrument(note->instrument), note->note, NULL) : song_get_sample(note->instrument); if (smp) { /* Modplug-specific hack: volume bit shift */ int n = smp->volume >> 2; note_text[6] = 0xbf; note_text[7] = '0' + n / 10 % 10; note_text[8] = '0' + n / 1 % 10; note_text[9] = 0xc0; } }
void update_current_instrument(void) { int ins_mode, n; char *name = NULL; char buf[4]; if (page_is_instrument_list(status.current_page) || status.current_page == PAGE_SAMPLE_LIST || status.current_page == PAGE_LOAD_SAMPLE || status.current_page == PAGE_LIBRARY_SAMPLE || (!(status.flags & CLASSIC_MODE) && (status.current_page == PAGE_ORDERLIST_PANNING || status.current_page == PAGE_ORDERLIST_VOLUMES))) ins_mode = 0; else ins_mode = song_is_instrument_mode(); if (ins_mode) { draw_text("Instrument", 39, 3, 0, 2); n = instrument_get_current(); if (n > 0) name = song_get_instrument(n)->name; } else { draw_text(" Sample", 39, 3, 0, 2); n = sample_get_current(); if (n > 0) name = song_get_sample(n)->name; } if (n > 0) { draw_text(num99tostr(n, buf), 50, 3, 5, 0); draw_text_len(name, 25, 53, 3, 5, 0); } else { draw_text("..", 50, 3, 5, 0); draw_text(".........................", 53, 3, 5, 0); } }
int fmt_pat_load_instrument(const uint8_t *data, size_t length, int slot) { struct GF1PatchHeader header; struct GF1PatchSampleHeader gfsamp; struct instrumentloader ii; song_instrument_t *g; song_sample_t *smp; unsigned int pos, rs; int lo, hi, tmp, i, nsamp, n; if (length < sizeof(header) || !slot) return 0; memcpy(&header, data, sizeof(header)); if ((memcmp(header.sig, "GF1PATCH", 8) != 0) || (memcmp(header.ver, "110\0", 4) != 0 && memcmp(header.ver, "100\0", 4) != 0) || (memcmp(header.id, "ID#000002\0", 10) != 0)) { return 0; } header.waveforms = bswapLE16(header.waveforms); header.mastervol = bswapLE16(header.mastervol); header.datasize = bswapLE32(header.datasize); header.insID = bswapLE16(header.insID); header.inssize = bswapLE32(header.inssize); header.layersize = bswapLE32(header.layersize); g = instrument_loader_init(&ii, slot); memcpy(g->name, header.insname, 16); g->name[15] = '\0'; nsamp = CLAMP(header.smpnum, 1, 16); pos = sizeof(header); for (i = 0; i < 120; i++) { g->sample_map[i] = 0; g->note_map[i] = i + 1; } for (i = 0; i < nsamp; i++) { memcpy(&gfsamp, data + pos, sizeof(gfsamp)); pos += sizeof(gfsamp); n = instrument_loader_sample(&ii, i + 1) - 1; smp = song_get_sample(n); gfsamp.samplesize = bswapLE32(gfsamp.samplesize); gfsamp.loopstart = bswapLE32(gfsamp.loopstart); gfsamp.loopend = bswapLE32(gfsamp.loopend); gfsamp.samplerate = bswapLE16(gfsamp.samplerate); gfsamp.lofreq = bswapLE32(gfsamp.lofreq); gfsamp.hifreq = bswapLE32(gfsamp.hifreq); gfsamp.rtfreq = bswapLE32(gfsamp.rtfreq); gfsamp.tune = bswapLE16(gfsamp.tune); gfsamp.scalefreq = bswapLE16(gfsamp.scalefac); lo = CLAMP(gusfreq(gfsamp.lofreq), 0, 95); hi = CLAMP(gusfreq(gfsamp.hifreq), 0, 95); if (lo > hi) { tmp = lo; lo = hi; hi = tmp; } for (; lo < hi; lo++) { g->sample_map[lo + 12] = n; } if (gfsamp.smpmode & 1) { gfsamp.samplesize >>= 1; gfsamp.loopstart >>= 1; gfsamp.loopend >>= 1; } smp->length = gfsamp.samplesize; smp->loop_start = smp->sustain_start = gfsamp.loopstart; smp->loop_end = smp->sustain_end = gfsamp.loopend; smp->c5speed = gfsamp.samplerate; smp->flags = 0; rs = SF_M | SF_LE; // channels; endianness rs |= (gfsamp.smpmode & 1) ? SF_16 : SF_8; // bit width rs |= (gfsamp.smpmode & 2) ? SF_PCMU : SF_PCMS; // encoding if (gfsamp.smpmode & 32) { if (gfsamp.smpmode & 4) smp->flags |= CHN_SUSTAINLOOP; if (gfsamp.smpmode & 8) smp->flags |= CHN_PINGPONGSUSTAIN; } else { if (gfsamp.smpmode & 4) smp->flags |= CHN_LOOP; if (gfsamp.smpmode & 8) smp->flags |= CHN_PINGPONGLOOP; } memcpy(smp->filename, gfsamp.wavename, 7); smp->filename[8] = '\0'; strcpy(smp->name, smp->filename); smp->vib_speed = gfsamp.vib_speed; smp->vib_rate = gfsamp.vib_rate; smp->vib_depth = gfsamp.vib_depth; pos += csf_read_sample(current_song->samples + n, rs, data + pos, length - pos); }