Ejemplo n.º 1
0
static void
midireset(CMMIDI midi)
{
	const UINT8 *excv;
	UINT excvsize;
	UINT8 work[4];

	switch (midi->midimodule) {
	case MIDI_GM:
		excv = EXCV_GMRESET;
		excvsize = sizeof(EXCV_GMRESET);
		break;

	case MIDI_CM300:
	case MIDI_CM500GS:
	case MIDI_SC55:
	case MIDI_SC88:
	case MIDI_GS:
		excv = EXCV_GSRESET;
		excvsize = sizeof(EXCV_GSRESET);
		break;

	case MIDI_XG:
		excv = EXCV_XGRESET;
		excvsize = sizeof(EXCV_XGRESET);
		break;

	case MIDI_MT32:
	case MIDI_CM32L:
	case MIDI_CM64:
	case MIDI_CM500LA:
	case MIDI_LA:
		excv = EXCV_MTRESET;
		excvsize = sizeof(EXCV_MTRESET);
		break;

	default:
		excv = NULL;
		excvsize = 0;
		break;
	}
	if (excv) {
		if (midi->opened & CMMIDI_MIDIOUT) {
			waitlastexclusiveout(midi);
			sendexclusive(midi, excv, excvsize);
		}
#if defined(VERMOUTH_LIB)
		else if (midi->opened & CMMIDI_VERMOUTH) {
			midiout_longmsg(midi->vermouth, excv, excvsize);
		}
#endif
	}

	work[1] = 0x7b;
	work[2] = 0x00;
	for (work[0] = 0xb0; work[0] < 0xc0; work[0]++) {
		keydisp_midi(work);
		(*midi->outfn)(midi, MIDIOUTS3(work), 3);
	}
}
Ejemplo n.º 2
0
static void midiallnoteoff(CMMIDI midi) {

	UINT	i;
	UINT8	msg[4];

	for (i=0; i<0x10; i++) {
		msg[0] = (UINT8)(0xb0 + i);
		msg[1] = 0x7b;
		msg[2] = 0x00;
		keydisp_midi(msg);
		midi->shortout(midi, MIDIOUTS3(msg));
	}
}
Ejemplo n.º 3
0
static void midireset(CMMIDI midi) {

	UINT8	work[4];

	midiout_longmsg(midi->midihdl, EXCV_GMRESET, sizeof(EXCV_GMRESET));

	work[1] = 0x7b;
	work[2] = 0x00;
	for (work[0]=0xb0; work[0]<0xc0; work[0]++) {
		keydisp_midi(work);
		sound_sync();
		midiout_shortmsg(midi->midihdl, MIDIOUTS3(work));
	}
}
Ejemplo n.º 4
0
static UINT midiwrite(COMMNG self, UINT8 data) {

	CMMIDI	midi;
	MIDICH	mch;

	midi = (CMMIDI)(self + 1);
	switch(data) {
		case MIDI_TIMING:
		case MIDI_START:
		case MIDI_CONTINUE:
		case MIDI_STOP:
		case MIDI_ACTIVESENSE:
		case MIDI_SYSTEMRESET:
			return(1);
	}
	if (midi->midictrl == MIDICTRL_READY) {
		if (data & 0x80) {
			midi->mpos = 0;
			switch(data & 0xf0) {
				case 0xc0:
				case 0xd0:
					midi->midictrl = MIDICTRL_2BYTES;
					break;

				case 0x80:
				case 0x90:
				case 0xa0:
				case 0xb0:
				case 0xe0:
					midi->midictrl = MIDICTRL_3BYTES;
					midi->midilast = data;
					break;

				default:
					switch(data) {
						case MIDI_EXCLUSIVE:
							midi->midictrl = MIDICTRL_EXCLUSIVE;
							break;

						case MIDI_TIMECODE:
							midi->midictrl = MIDICTRL_TIMECODE;
							break;

						case MIDI_SONGPOS:
							midi->midictrl = MIDICTRL_SYSTEM;
							midi->midisyscnt = 3;
							break;

						case MIDI_SONGSELECT:
							midi->midictrl = MIDICTRL_SYSTEM;
							midi->midisyscnt = 2;
							break;

						case MIDI_TUNEREQUEST:
							midi->midictrl = MIDICTRL_SYSTEM;
							midi->midisyscnt = 1;
							break;

//						case MIDI_EOX:
						default:
							return(1);
					}
					break;
			}
		}
		else {						// Key-onのみな気がしたんだけど忘れた…
			// running status
			midi->buffer[0] = midi->midilast;
			midi->mpos = 1;
			midi->midictrl = MIDICTRL_3BYTES;
		}
	}
	midi->buffer[midi->mpos] = data;
	midi->mpos++;

	switch(midi->midictrl) {
		case MIDICTRL_2BYTES:
			if (midi->mpos >= 2) {
				midi->buffer[1] &= 0x7f;
				mch = midi->mch + (midi->buffer[0] & 0xf);
				switch(midi->buffer[0] & 0xf0) {
					case 0xa0:
						mch->press = midi->buffer[1];
						break;

					case 0xc0:
						mch->prog = midi->buffer[1];
						break;
				}
				keydisp_midi(midi->buffer);
				sound_sync();
				midiout_shortmsg(midi->midihdl, MIDIOUTS2(midi->buffer));
				midi->midictrl = MIDICTRL_READY;
				return(2);
			}
			break;

		case MIDICTRL_3BYTES:
			if (midi->mpos >= 3) {
				midi->buffer[1] &= 0x7f;
				midi->buffer[2] &= 0x7f;
				mch = midi->mch + (midi->buffer[0] & 0xf);
				switch(midi->buffer[0] & 0xf0) {
					case 0xb0:
						if (midi->buffer[1] == 123) {
							mch->press = 0;
							mch->bend = 0x4000;
							mch->ctrl[1+1] = 0;			// Modulation
							mch->ctrl[5+1] = 127;		// Explession
							mch->ctrl[6+1] = 0;			// Hold
							mch->ctrl[7+1] = 0;			// Portament
							mch->ctrl[8+1] = 0;			// Sostenute
							mch->ctrl[9+1] = 0;			// Soft
						}
						else {
							mch->ctrl[midictrlindex[midi->buffer[1]]]
															= midi->buffer[2];
						}
						break;

					case 0xe0:
						mch->bend = LOADINTELWORD(midi->buffer + 1);
						break;
				}
				keydisp_midi(midi->buffer);
				sound_sync();
				midiout_shortmsg(midi->midihdl, MIDIOUTS3(midi->buffer));
				midi->midictrl = MIDICTRL_READY;
				return(3);
			}
			break;

		case MIDICTRL_EXCLUSIVE:
			if (data == MIDI_EOX) {
				midiout_longmsg(midi->midihdl, midi->buffer, midi->mpos);
				midi->midictrl = MIDICTRL_READY;
				return(midi->mpos);
			}
			else if (midi->mpos >= MIDI_BUFFER) {		// おーばーふろー
				midi->midictrl = MIDICTRL_READY;
			}
			break;

		case MIDICTRL_TIMECODE:
			if (midi->mpos >= 2) {
				if ((data == 0x7e) || (data == 0x7f)) {
					// exclusiveと同じでいい筈…
					midi->midictrl = MIDICTRL_EXCLUSIVE;
				}
				else {
					midi->midictrl = MIDICTRL_READY;
					return(2);
				}
			}
			break;

		case MIDICTRL_SYSTEM:
			if (midi->mpos >= midi->midisyscnt) {
				midi->midictrl = MIDICTRL_READY;
				return(midi->midisyscnt);
			}
			break;
	}
	return(0);
}
Ejemplo n.º 5
0
static UINT
midiwrite(COMMNG self, UINT8 data)
{
	CMMIDI midi;
	MIDICH mch;
	int type;

	midi = (CMMIDI)(self + 1);
	switch (data) {
	case MIDI_TIMING:
	case MIDI_START:
	case MIDI_CONTINUE:
	case MIDI_STOP:
	case MIDI_ACTIVESENSE:
	case MIDI_SYSTEMRESET:
		return 1;
	}
	if (midi->midictrl == MIDICTRL_READY) {
		if (data & 0x80) {
			midi->mpos = 0;
			switch (data & 0xf0) {
			case 0xc0:
			case 0xd0:
				midi->midictrl = MIDICTRL_2BYTES;
				break;

			case 0x80:
			case 0x90:
			case 0xa0:
			case 0xb0:
			case 0xe0:
				midi->midictrl = MIDICTRL_3BYTES;
				midi->midilast = data;
				break;

			default:
				switch (data) {
				case MIDI_EXCLUSIVE:
					midi->midictrl = MIDICTRL_EXCLUSIVE;
					break;

				case MIDI_TIMECODE:
					midi->midictrl = MIDICTRL_TIMECODE;
					break;

				case MIDI_SONGPOS:
					midi->midictrl = MIDICTRL_SYSTEM;
					midi->midisyscnt = 3;
					break;

				case MIDI_SONGSELECT:
					midi->midictrl = MIDICTRL_SYSTEM;
					midi->midisyscnt = 2;
					break;

				case MIDI_TUNEREQUEST:
					midi->midictrl = MIDICTRL_SYSTEM;
					midi->midisyscnt = 1;
					break;

#if 0
				case MIDI_EOX:
#endif
				default:
					return(1);
				}
				break;
			}
		} else { /* Key-onのみな気がしたんだけど忘れた… */
			/* running status */
			midi->buffer[0] = midi->midilast;
			midi->mpos = 1;
			midi->midictrl = MIDICTRL_3BYTES;
		}
	}
	midi->buffer[midi->mpos] = data;
	midi->mpos++;

	switch (midi->midictrl) {
	case MIDICTRL_2BYTES:
		if (midi->mpos >= 2) {
			midi->buffer[1] &= 0x7f;
			mch = midi->mch + (midi->buffer[0] & 0xf);
			switch (midi->buffer[0] & 0xf0) {
			case 0xa0:
				mch->press = midi->buffer[1];
				break;

			case 0xc0:
				if (midi->def_en) {
					type = midi->def.ch[midi->buffer[0] & 0x0f];
					if (type < MIMPI_RHYTHM) {
						midi->buffer[1] = midi->def.map[type][midi->buffer[1]];
					}
				}
				mch->prog = midi->buffer[1];
				break;
			}
			keydisp_midi(midi->buffer);
			(*midi->outfn)(midi, MIDIOUTS2(midi->buffer), 2);
			midi->midictrl = MIDICTRL_READY;
			return 2;
		}
		break;

	case MIDICTRL_3BYTES:
		if (midi->mpos >= 3) {
			midi->buffer[1] &= 0x7f;
			midi->buffer[2] &= 0x7f;
			mch = midi->mch + (midi->buffer[0] & 0xf);
			switch (midi->buffer[0] & 0xf0) {
			case 0xb0:
				if (midi->buffer[1] == 123) {
					mch->press = 0;
					mch->bend = 0x4000;
					mch->ctrl[1+1] = 0;	// Modulation
					mch->ctrl[5+1] = 127;	// Explession
					mch->ctrl[6+1] = 0;	// Hold
					mch->ctrl[7+1] = 0;	// Portament
					mch->ctrl[8+1] = 0;	// Sostenute
					mch->ctrl[9+1] = 0;	// Soft
				} else {
					mch->ctrl[midictrlindex[midi->buffer[1]]] = midi->buffer[2];
				}
				break;

			case 0xe0:
				mch->bend = LOADINTELWORD(midi->buffer + 1);
				break;
			}
			keydisp_midi(midi->buffer);
			(*midi->outfn)(midi, MIDIOUTS3(midi->buffer), 3);
			midi->midictrl = MIDICTRL_READY;
			return 3;
		}
		break;

	case MIDICTRL_EXCLUSIVE:
		if (data == MIDI_EOX) {
			if (midi->opened & CMMIDI_MIDIOUT) {
				waitlastexclusiveout(midi);
				sendexclusive(midi, midi->buffer, midi->mpos);
			}
#if defined(VERMOUTH_LIB)
			else if (midi->opened & CMMIDI_VERMOUTH) {
				midiout_longmsg(midi->vermouth, midi->buffer, midi->mpos);
			}
#endif
			midi->midictrl = MIDICTRL_READY;
			return midi->mpos;
		} else if (midi->mpos >= MIDI_BUFFER) {	// おーばーふろー
			midi->midictrl = MIDICTRL_READY;
		}
		break;

	case MIDICTRL_TIMECODE:
		if (midi->mpos >= 2) {
			if ((data == 0x7e) || (data == 0x7f)) {
				// exclusiveと同じでいい筈…
				midi->midictrl = MIDICTRL_EXCLUSIVE;
			} else {
				midi->midictrl = MIDICTRL_READY;
				return 2;
			}
		}
		break;

	case MIDICTRL_SYSTEM:
		if (midi->mpos >= midi->midisyscnt) {
			midi->midictrl = MIDICTRL_READY;
			return midi->midisyscnt;
		}
		break;
	}
	return 0;
}