📄 mac_qt_a.c
字号:
switch(program){ case 38: return kFirstGSInstrument + (16<<7) + 39; // Rubber Bass case 80: return kFirstGSInstrument + (8<<7) + 80; // Sine Wave case 117: return kFirstGSInstrument + (8<<7) + 117; // Melo.Tom 2 } break; case 96: switch(program){ case 14: return kFirstGSInstrument + (8<<7) + 14; // Church Bell case 24: return kFirstGSInstrument + (8<<7) + 24; // Ukulele case 25: return kFirstGSInstrument + (16<<7) + 25; // Mandolin case 107: return kFirstGSInstrument + (8<<7) + 107; // Taisho Koto case 115: return kFirstGSInstrument + (8<<7) + 115; // Castanets } break; case 97: switch(program){ case 14: return kFirstGSInstrument + (9<<7) + 14; // Carillon } break; } return kFirstGMInstrument + program;}static void set_instrument(MidiEvent *ev){ long instrumentNumber; int ch = ev->channel; channel[ch].program = ev->a; if(drum_part[ch]){ if(play_system_mode == GS_SYSTEM_MODE && channel[ch].bank_lsb == 2) // SC-88 Map instrumentNumber = kFirstDrumkit + sc88_drum_kit[ev->a] + 1; else if(play_system_mode == GS_SYSTEM_MODE && channel[ch].bank_lsb == 3) // SC-88Pro Map instrumentNumber = kFirstDrumkit + sc88pro_drum_kit[ev->a] + 1; else instrumentNumber = kFirstDrumkit + ev->a + 1; } else { if(play_system_mode == GS_SYSTEM_MODE) instrumentNumber = kFirstGSInstrument + (channel[ch].bank_msb<<7) + ev->a; else if(play_system_mode == XG_SYSTEM_MODE) instrumentNumber = xg_instrument_number(ch, ev->a); else instrumentNumber = kFirstGMInstrument + ev->a; } if(instrument_number[ch] != instrumentNumber){ NoteRequest nr; long index, part; OSType synthType; Str31 name; SynthesizerConnections connections; MusicComponent mc; char tmp[256]; /* enough */ instrument_number[ch] = instrumentNumber; if(note_channel[ch] != NULL) NADisposeNoteChannel(gNoteAllocator, note_channel[ch]); nr.info.flags = 0; if (qt5orlater && ch <= 16) nr.info.midiChannelAssignment = kNoteRequestSpecifyMIDIChannel | ch; else nr.info.midiChannelAssignment = 0; // see note QuickTimeMusic.h. *(short *)(&nr.info.polyphony) = EndianS16_NtoB(8); // 8 voices poliphonic *(Fixed *)(&nr.info.typicalPolyphony) = EndianU32_NtoB(0x00010000); NAStuffToneDescription(gNoteAllocator, instrumentNumber, &nr.tone); NANewNoteChannel(gNoteAllocator, &nr, ¬e_channel[ch]); NAGetNoteChannelInfo(gNoteAllocator, note_channel[ch], &index, &part); NAGetRegisteredMusicDevice(gNoteAllocator, index, &synthType, name, &connections, &mc); MusicGetPartName(mc, part, name); p2cstrcpy(tmp, name); strncpy(instrument_name[ch], tmp, sizeof(instrument_name[ch])); } ctl_prog_event(ch, ev->a);}static void play_event_prescan(void *p){ MidiEvent *ev = (MidiEvent *)p; int ch; for(ch = 0; ch < MAX_CHANNELS; ch++){ if(note_channel[ch] != NULL){ NADisposeNoteChannel(gNoteAllocator, note_channel[ch]); note_channel[ch] = NULL; } instrument_number[ch] = -1; instrument_name[ch][0] = '\0'; drum_part[ch] = false; channel[ch].bank_lsb = 0; channel[ch].bank_msb = 0; } drum_part[9] = true; for(;; ev++){ ch = ev->channel; if(ev->type == ME_NOTEON && note_channel[ch] == NULL){ //MidiEvent *ev; ev->channel = ch; ev->a = 0; set_instrument(ev); } else if(ev->type == ME_PROGRAM){ set_instrument(ev); } else if(ev->type == ME_TONE_BANK_LSB && ev->a != channel[ch].bank_lsb){ channel[ch].bank_lsb = ev->a; } else if(ev->type == ME_TONE_BANK_MSB && ev->a != channel[ch].bank_msb){ channel[ch].bank_msb = ev->a; if(play_system_mode == XG_SYSTEM_MODE && (ev->a == 126 || ev->a == 127) && !drum_part[ch]) drum_part[ch] = true; } else if(ev->type == ME_DRUMPART && !drum_part[ch]){ //MidiEvent *ev; ev->channel = ch; ev->a = channel[ch].program; set_instrument(ev); drum_part[ch] = true; } else if(ev->type == ME_RESET){ play_system_mode = ev->a; } else if(ev->type == ME_EOT){ prescan = 1; for(ch = 0; ch < MAX_CHANNELS; ch++){ channel[ch].bank_lsb = 0; channel[ch].bank_msb = 0; } init_variable(); break; } }}static int wait_event_time(void *p){ MidiEvent *ev = (MidiEvent *)p; int rc, ch; for(;;){ if(ev->time - (current_tick()*play_mode->rate+30)/60 < 0) break; trace_loop(); YieldToAnyThread(); rc = check_apply_control(); if(RC_IS_SKIP_FILE(rc)){ prescan = 0; for(ch = 0; ch < MAX_CHANNELS; ch++){ if(note_channel[ch] != NULL){ NADisposeNoteChannel(gNoteAllocator, note_channel[ch]); note_channel[ch] = NULL; } channel[ch].bank_lsb = 0; channel[ch].bank_msb = 0; } trace_flush(); return rc; } } return RC_NONE;}static void qt_play_event(void *p){ MidiEvent *ev = (MidiEvent *)p; int ch, i; ch = ev->channel; switch(ev->type) { case ME_NOTEON: if(play_system_mode == XG_SYSTEM_MODE && channel[ch].bank_msb == 127 && ev->a >= XG_DRUM_VOICE_FIRST_NOTE && ev->a <= XG_DRUM_VOICE_LAST_NOTE){ int a = ev->a - XG_DRUM_VOICE_FIRST_NOTE; a = xg_drum_voice[a][1]; NAPlayNote(gNoteAllocator, note_channel[ch], a, ev->b); qt_ctl_note_event(ch, ev->a, ev->b); } else if(play_system_mode == XG_SYSTEM_MODE && channel[ch].bank_msb == 126){ NAPlayNote(gNoteAllocator, note_channel[ch], ev->a, ev->b); qt_ctl_note_event(ch, ev->a, ev->b); } else { NAPlayNote(gNoteAllocator, note_channel[ch], ev->a, ev->b); qt_ctl_note_event(ch, ev->a, ev->b); } break; case ME_NOTEOFF: if(play_system_mode == XG_SYSTEM_MODE && channel[ch].bank_msb == 127 && ev->a >= XG_DRUM_VOICE_FIRST_NOTE && ev->a <= XG_DRUM_VOICE_LAST_NOTE){ int a = ev->a - XG_DRUM_VOICE_FIRST_NOTE; a = xg_drum_voice[a][1]; NAPlayNote(gNoteAllocator, note_channel[ch], a, 0); qt_ctl_note_event(ch, ev->a, 0); } else if(play_system_mode == XG_SYSTEM_MODE && channel[ch].bank_msb == 126){ NAPlayNote(gNoteAllocator, note_channel[ch], ev->a, 0); qt_ctl_note_event(ch, ev->a, 0); } else { NAPlayNote(gNoteAllocator, note_channel[ch], ev->a, 0); qt_ctl_note_event(ch, ev->a, 0); } break; case ME_PROGRAM: set_instrument(ev); break; /* MIDI Events */ case ME_KEYPRESSURE: case ME_CHANNEL_PRESSURE: NASetController(gNoteAllocator, note_channel[ch], kControllerAfterTouch, ev->a<<8); break; case ME_PITCHWHEEL: // kControllerPitchBend 256/halfnote i = (ev->b<<7) + ev->a - 0x2000; i *= (bend_sense[ch]<<1); i += (i > 0 ? (1<<12) : -(1<<12)); i >>= 13; NASetController(gNoteAllocator, note_channel[ch], kControllerPitchBend, i); break; /* Controls */ case ME_TONE_BANK_LSB: channel[ch].bank_lsb = ev->a; break; case ME_TONE_BANK_MSB: channel[ch].bank_msb = ev->a; if(play_system_mode == XG_SYSTEM_MODE && (ev->a == 126 || ev->a == 127) && !drum_part[ch]) drum_part[ch] = true; break; case ME_MODULATION_WHEEL: NASetController(gNoteAllocator, note_channel[ch], kControllerModulationWheel, ev->a); break; case ME_BREATH: NASetController(gNoteAllocator, note_channel[ch], kControllerBreath, ev->a<<8); break; case ME_FOOT: NASetController(gNoteAllocator, note_channel[ch], kControllerFoot, ev->a<<8); break; case ME_BALANCE: NASetController(gNoteAllocator, note_channel[ch], kControllerBalance, ev->a<<8); break; case ME_MAINVOLUME: NASetController(gNoteAllocator, note_channel[ch], kControllerVolume, ev->a<<8); break; case ME_PAN: // kControllerPan 256-512 NASetController(gNoteAllocator, note_channel[ch], kControllerPan, (ev->a<<1) + 256); ctl_mode_event(CTLE_PANNING, 1, ch, ev->a); break; case ME_EXPRESSION: NASetController(gNoteAllocator, note_channel[ch], kControllerExpression, ev->a<<8); ctl_mode_event(CTLE_EXPRESSION, 1, ch, ev->a); break; case ME_SUSTAIN: // kControllerSustain on/off only NASetController(gNoteAllocator, note_channel[ch], kControllerSustain, ev->a<<8); ctl_mode_event(CTLE_SUSTAIN, 1, ch, ev->a); break; case ME_PORTAMENTO_TIME_MSB: channel[ch].portamento_time_msb = ev->a; NASetController(gNoteAllocator, note_channel[ch], kControllerPortamentoTime, (channel[ch].portamento_time_msb + (channel[ch].portamento_time_lsb<<7))<<1); break; case ME_PORTAMENTO_TIME_LSB: channel[ch].portamento_time_lsb = ev->a; NASetController(gNoteAllocator, note_channel[ch], kControllerPortamentoTime, (channel[ch].portamento_time_msb + (channel[ch].portamento_time_lsb<<7))<<1); break; case ME_PORTAMENTO: NASetController(gNoteAllocator, note_channel[ch], kControllerPortamento, ev->a<<8); break; case ME_DATA_ENTRY_MSB: if(rpn_flag){ if(rpn_addr[ch] == 0) // pitchbend sensitivity bend_sense[ch] = (ev->a<<7) + ev->b; else if(rpn_addr[ch] == 1){ // master tuning (fine) master_tune[ch] |= ev->a; NASetController(gNoteAllocator, note_channel[ch], kControllerMasterTune, master_tune[ch]); } else if(rpn_addr[ch] == 2){ // master tuning (coarse) master_tune[ch] |= (ev->a<<7); NASetController(gNoteAllocator, note_channel[ch], kControllerMasterTune, master_tune[ch]); } } else { } break; case ME_REVERB_EFFECT: NASetController(gNoteAllocator, note_channel[ch], kControllerReverb, ev->a<<8); channel[ch].reverb_level = ev->a; ctl_mode_event(CTLE_REVERB_EFFECT, 1, ch, ev->a); break; case ME_TREMOLO_EFFECT: NASetController(gNoteAllocator, note_channel[ch], kControllerTremolo, ev->a<<8); break; case ME_CHORUS_EFFECT: NASetController(gNoteAllocator, note_channel[ch], kControllerChorus, ev->a<<8); channel[ch].chorus_level = ev->a; ctl_mode_event(CTLE_CHORUS_EFFECT, 1, ch, ev->a); break; case ME_CELESTE_EFFECT: NASetController(gNoteAllocator, note_channel[ch], kControllerCeleste, ev->a<<8); break; case ME_PHASER_EFFECT: NASetController(gNoteAllocator, note_channel[ch], kControllerPhaser, ev->a<<8); break; case ME_RPN_INC: rpn_flag = 1; rpn_addr[ch]++; break; case ME_RPN_DEC: rpn_flag = 1; rpn_addr[ch]--; break; case ME_NRPN_LSB: rpn_flag = 0; nrpn_lsb[ch] = ev->a; break; case ME_NRPN_MSB: rpn_flag = 0; nrpn_msb[ch] = ev->a; break; case ME_RPN_LSB: rpn_flag = 1; rpn_addr[ch] = ev->a; break; case ME_RPN_MSB: break; case ME_ALL_SOUNDS_OFF: for(i = 0; i < 128; i++) NAPlayNote(gNoteAllocator, note_channel[ch], i, 0); break; case ME_RESET_CONTROLLERS: NAResetNoteChannel(gNoteAllocator, note_channel[ch]); ctl_mode_event(CTLE_VOLUME, 1, ch, 0); ctl_mode_event(CTLE_EXPRESSION, 1, ch, 127); ctl_mode_event(CTLE_SUSTAIN, 1, ch, 0); ctl_mode_event(CTLE_MOD_WHEEL, 1, ch, 0); ctl_mode_event(CTLE_PITCH_BEND, 1, ch, 0x2000); ctl_prog_event(ch, channel[ch].program); ctl_mode_event(CTLE_CHORUS_EFFECT, 1, ch, 0); ctl_mode_event(CTLE_REVERB_EFFECT, 1, ch, 0); break; case ME_ALL_NOTES_OFF: for(i = 0; i < 128; i++) NAPlayNote(gNoteAllocator, note_channel[ch], i, 0); break; case ME_MONO: break; case ME_POLY: break; case ME_SOSTENUTO: NASetController(gNoteAllocator, note_channel[ch], kControllerSostenuto, ev->a); break; case ME_SOFT_PEDAL: NASetController(gNoteAllocator, note_channel[ch], kControllerSoftPedal, ev->a); break; /* TiMidity Extensionals */ case ME_RANDOM_PAN: break; case ME_SET_PATCH: break; case ME_TEMPO: break; case ME_CHORUS_TEXT: case ME_LYRIC: case ME_MARKER: case ME_INSERT_TEXT: case ME_TEXT: case ME_KARAOKE_LYRIC: i = ev->a | ((int)ev->b << 8); ctl_mode_event(CTLE_LYRIC, 1, i, 0); break; case ME_MASTER_VOLUME: NASetController(gNoteAllocator, NULL, kControllerMasterVolume, ev->a + (ev->b<<7)); break; case ME_PATCH_OFFS: break; case ME_RESET: play_system_mode = ev->a; break; case ME_WRD: push_midi_trace2(wrd_midi_event, ch, ev->a | (ev->b<<8)); break; case ME_DRUMPART: if(!drum_part[ch]){ //MidiEvent *ev; ev->channel = ch; ev->a = channel[ch].program; set_instrument(ev); drum_part[ch] = true; } break; case ME_KEYSHIFT: NASetController(gNoteAllocator, NULL, kControllerMasterTune, ev->a); break; case ME_NOTE_STEP: break; case ME_EOT: prescan = 0; break; } if(ev->type != ME_EOT) ctl_timestamp();}static int acntl(int request, void *arg){ int rc, ch; switch(request) { case PM_REQ_MIDI: if(!prescan) play_event_prescan(arg); rc = wait_event_time(arg); if(RC_IS_SKIP_FILE(rc)) return rc; qt_play_event(arg); return RC_NONE; case PM_REQ_INST_NAME: ch = (int)*(char **)arg; *(char **)arg = instrument_name[ch]; return 0; case PM_REQ_GETSAMPLES: *(int32 *)arg = current_samples(); return 0; case PM_REQ_PLAY_START: init_variable(); case PM_REQ_DISCARD: case PM_REQ_FLUSH: for(ch = 0; ch < MAX_CHANNELS; ch++){ if(note_channel[ch] != NULL){ NADisposeNoteChannel(gNoteAllocator, note_channel[ch]); note_channel[ch] = NULL; } channel[ch].bank_lsb = 0; channel[ch].bank_msb = 0; } trace_flush(); return 0; } return -1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -