Parameter::~Parameter(void)
{
	char string[NUM_PARAMETERS*12];
	char tmpString[12];

	/* Stop midi */
	for (unsigned int devID = 0; devID < numDevices; devID++)
	{
		MMRESULT rc;
		rc = midiInReset(midiInDevice[devID]);
		rc = midiInStop(midiInDevice[devID]);
		rc = midiInClose(midiInDevice[devID]);
	}

#if 0
	/* Save to clipboard... */
	string[0] = 0;
	for (int par = 0; par < NUM_PARAMETERS; par++)
	{
		if (changed[par])
		{
			sprintf(tmpString, "%d:%.2f(%d) ", par, value[par], (int)(value[par]*127.0f + 0.49f));
			strcat(string, tmpString);
		}
	}

	CopyToClipboard(string);
#endif
}
Example #2
0
static void midirelease(COMMNG self) {

	CMMIDI	midi;

	midi = (CMMIDI)(self + 1);
	midiallnoteoff(midi);
	if (midi->opened & CMMIDI_MIDIOUT) {
		waitlastexclusiveout(midi);
		midiOutReset(midi->out.win32.hmidiout);
		midiOutClose(midi->out.win32.hmidiout);
	}
	if (midi->opened & CMMIDI_MIDIIN) {
		if (midi->opened & CMMIDI_MIDIINSTART) {
			midiInStop(midi->hmidiin);
			midiInUnprepareHeader(midi->hmidiin,
										&midi->hmidiinhdr, sizeof(MIDIHDR));
		}
		midiInReset(midi->hmidiin);
		midiInClose(midi->hmidiin);
		midiinhdlunreg(midi);
	}
#if defined(VERMOUTH_LIB)
	if (midi->opened & CMMIDI_VERMOUTH) {
		midiout_destroy(midi->out.vermouth);
	}
#endif
#if defined(MT32SOUND_DLL)
	if (midi->opened & CMMIDI_MT32SOUND) {
		mt32sound_close();
	}
#endif
	_MFREE(self);
}
Example #3
0
MInputDeviceWin32::~MInputDeviceWin32()
{
	if(hMidiIn) {
		midiInStop(hMidiIn);
		midiInClose(hMidiIn);
	}
}
static void msw_close_midiin(void)
{
    unsigned int i;
    /* Stop, reset, close MIDI input.  Free callback instance data.
     */

    for (i=0; (i<wNumDevices) && (i<MAXMIDIINDEV); i++)
    {
        if (hMidiIn[i])
        {
            if (sys_verbose)
                post("closing MIDI input %d...", i);
            midiInStop(hMidiIn[i]);
            midiInReset(hMidiIn[i]);
            midiInClose(hMidiIn[i]);
            FreeCallbackInstanceData(lpCallbackInstanceData[i]);
        }
    }
    
    /* Free input buffer.
     */
    if (lpInputBuffer)
        FreeCircularBuffer(lpInputBuffer);

    if (sys_verbose)
        post("...done");
    wNumDevices = 0;
}
Example #5
0
 bool Close()
 {
   for (int i = 0; i < nMIDIDeviceCount; i++) {
     midiInStop(hMIDIInput[i]);
     midiInClose(hMIDIInput[i]);
   }
   return true;
 }
Example #6
0
/* midi_win32_in_exit:
 */
void midi_win32_in_exit(int input)
{
   if (midi_in_device != NULL) {
      midiInStop(midi_in_device);
      midiInReset(midi_in_device);
      midiInClose(midi_in_device);
      midi_in_device = NULL;
   }
}
Example #7
0
int rtsyn_synth_start(){
	int i;
	UINT port;

#ifdef __W32__
	DWORD processPriority;
	processPriority = GetPriorityClass(GetCurrentProcess());
#endif

	
	port=0;
	sleep(2);
	for(port=0;port<rtsyn_portnumber;port++){
		for (i=0;i<MAX_EXBUF;i++){
			IMidiHdr[port][i] = (MIDIHDR *)sIMidiHdr[port][i];
			memset(IMidiHdr[port][i],0,sizeof(MIDIHDR));
			IMidiHdr[port][i]->lpData = sImidiHdr_data[port][i];
			memset((IMidiHdr[port][i]->lpData),0,BUFF_SIZE);
			IMidiHdr[port][i]->dwBufferLength = BUFF_SIZE;
		}
	}
	evbwpoint=0;
	evbrpoint=0;
	mvbuse=0;

	for(port=0;port<rtsyn_portnumber;port++){
		midiInOpen(&hMidiIn[port],portID[port],(DWORD)MidiInProc,(DWORD)port,CALLBACK_FUNCTION);
		for (i=0;i<MAX_EXBUF;i++){
			midiInUnprepareHeader(hMidiIn[port],IMidiHdr[port][i],sizeof(MIDIHDR));
			midiInPrepareHeader(hMidiIn[port],IMidiHdr[port][i],sizeof(MIDIHDR));
			midiInAddBuffer(hMidiIn[port],IMidiHdr[port][i],sizeof(MIDIHDR));
		}
	}

#ifdef __W32__
	// HACK:midiInOpen()でリセットされてしまうため、再設定
	SetPriorityClass(GetCurrentProcess(), processPriority);
#endif
	for(port=0;port<rtsyn_portnumber;port++){
		if(MMSYSERR_NOERROR !=midiInStart(hMidiIn[port])){
			int i;
			for(i=0;i<port;i++){
				midiInStop(hMidiIn[i]);
				midiInReset(hMidiIn[i]);
				midiInClose(hMidiIn[i]);
			}
			goto winmmerror;
		}
	}
	mim_start_time = get_current_calender_time();
	InitializeCriticalSection(&mim_section);
	return ~0;

winmmerror:
	ctl->cmsg(  CMSG_ERROR, VERB_NORMAL, "midiInStarterror\n" );
	return 0;
}
Example #8
0
		void Stop()
		{
			if (handle)
			{
				// stop midi input
				stopping = true;
				midiInStop(handle);
			}
		}
Example #9
0
//---------------------------------------------------------------------------//
// End
//
//---------------------------------------------------------------------------//
void CMidiDevice::End()
{
    if (m_Ok)
    {
        midiInStop (m_MidiIn);
        midiInClose(m_MidiIn);
        m_Ok = false;
    }
}
Example #10
0
		bool _reset(uint _deviceID) 
		{
			MMRESULT res;
			if ( ! _midiIn ) return 0;
			res = midiInStop( _midiIn );
			if ( res ) return _error( res );   
			res = midiInReset( _midiIn );
			if ( res ) return _error( res );   
			res = midiInStart( _midiIn );
			return  _error( res );   
		}
Example #11
0
		bool _close() 
		{
			MMRESULT res;
			if ( ! _midiIn ) return 0;
			res = midiInStop( _midiIn );
			if ( res ) return _error( res );   
			res = midiInClose( _midiIn );
			if ( res ) return _error( res );   
			_midiIn = 0;
			_call = 0;
			return 1;
		}
/*
 * delete_fluid_winmidi_driver
 */
int
delete_fluid_winmidi_driver(fluid_midi_driver_t* p)
{
  fluid_winmidi_driver_t* dev = (fluid_winmidi_driver_t*) p;
  if (dev->hmidiin != NULL) {
    midiInStop(dev->hmidiin);
    midiInReset(dev->hmidiin);
    midiInClose(dev->hmidiin);
  }
  FLUID_FREE(dev);
  return 0;
}
Example #13
0
 void stop()
 {
     if (isStarted)
     {
         isStarted = false;
         midiInReset (deviceHandle);
         midiInStop (deviceHandle);
         activeMidiCollectors.removeValue (this);
         unprepareAllHeaders();
         concatenator.reset();
     }
 }
Example #14
0
void rtsyn_midiports_close(void){
	UINT port;
	
	for(port=0;port<rtsyn_portnumber;port++){
		if( MMSYSERR_NOERROR!=midiInStop(hMidiIn[port]) )
			ctl->cmsg(  CMSG_ERROR, VERB_NORMAL,"MIDI Stop Error\n");
		if( MMSYSERR_NOERROR!=midiInReset(hMidiIn[port]) ) 
			ctl->cmsg(  CMSG_ERROR, VERB_NORMAL,"MIDI Rest Error\n");
		if( MMSYSERR_NOERROR!=midiInClose(hMidiIn[port]) ) 
			ctl->cmsg(  CMSG_ERROR, VERB_NORMAL,"MIDI Close Error\n");
	}
}
BOOL WINAPI control_handler(DWORD control_type)
{
	midiInStop(midi_in);
	midiInClose(midi_in);

	Pa_StopStream(audio_stream);
	Pa_CloseStream(audio_stream);
	Pa_Terminate();

	Beatbox_free(beatbox);

	return FALSE;
}
Example #16
0
void JMIDIInObj::close() {
  cs.lock();
  if (!connected) goto CSEND;
  connected = false;
#if defined(WIN32)
  midiInStop((HMIDIIN)handle);
  midiInReset((HMIDIIN)handle);
  midiInUnprepareHeader((HMIDIIN)handle, 
    (MIDIHDR*)(char*)data, sizeof(MIDIHDR));
  midiInClose((HMIDIIN)handle);
#endif
  handle = -1;
  data.Release();
  repaint();
CSEND:;
  cs.unlock();
}
Example #17
0
MidiUartWinClass::~MidiUartWinClass() {
  if (inHandle != (HMIDIIN)-1) {
    if (midiInStop(inHandle) != MMSYSERR_NOERROR) {
      throw "Could not stop MIDI input";
    }
    if (midiInReset(inHandle) != MMSYSERR_NOERROR) {
      throw "Could reset MIDI input";
    }
    if (midiInClose(inHandle) != MMSYSERR_NOERROR) {
      throw "Could not close MIDI input";
    }
		
    midiInUnprepareHeader(inHandle, &midiHdr, sizeof(MIDIHDR));
  }

  if (outHandle != (HMIDIOUT)-1) {
    midiOutClose(outHandle);
  }
}
Example #18
0
void midiClose(void) {
  MMRESULT res;
  
  //  printf("stop\n");
  if (MMSYSERR_NOERROR != midiInStop(inHandle)) {
    logPrintf(LOG_ERROR, "input stop error\n");
  }
  //  printf("reset\n");
  if (MMSYSERR_NOERROR != midiInReset(inHandle)) {
    logPrintf(LOG_ERROR, "input reset error\n");
  }

  int retry = 0;
  do {
    res = midiInClose(inHandle);
    if (res != MMSYSERR_NOERROR) {
      logPrintf(LOG_ERROR, "input close error\n");
    }
    if (res == MIDIERR_STILLPLAYING) {
      midiInReset(inHandle);
    }
    Sleep(10);
    retry++;
  } while ((res == MIDIERR_STILLPLAYING) && (retry < 10));
  
  midiInUnprepareHeader(inHandle, &midiHdr, sizeof(MIDIHDR));

  retry = 0;
  res = midiOutReset(outHandle);
  if (res != MMSYSERR_NOERROR) {
    logPrintf(LOG_ERROR, "output reset error\n");
  }
  do {
    res = midiOutClose(outHandle);
    if (res != MMSYSERR_NOERROR) {
      logPrintf(LOG_ERROR, "output close error\n");
    }
    Sleep(10);
    retry++;
  } while ((res == MIDIERR_STILLPLAYING) && (retry < 10));
}
Example #19
0
void archMidiEnable(int enable)
{
    int i;

    midi.enabled = enable;
    if (midi.out.current[0] != NULL) {
        midiOutSetVolume((HMIDIOUT)midi.out.current[0]->handle, midi.out.volume * midi.enabled);
    }
    for (i = 0; i < 2; i++) {
        if (midi.in.current[i] != NULL) {
            if (enable && !midi.in.current[i]->recording) {
                midiInStart((HMIDIIN)midi.in.current[i]->handle);
                midi.in.current[i]->recording = 1;
            }
            else if (!enable && midi.in.current[i]->recording) {
                midiInStop((HMIDIIN)midi.in.current[i]->handle);
                midi.in.current[i]->recording = 0;
            }
        }
    }
}
Example #20
0
void RtMidiIn :: closePort( void )
{
  if ( connected_ ) {
    WinMidiData *data = static_cast<WinMidiData *> (apiData_);
    midiInReset( data->inHandle );
    midiInStop( data->inHandle );

    for ( int i=0; i<RT_SYSEX_BUFFER_COUNT; ++i ) {
      int result = midiInUnprepareHeader(data->inHandle, data->sysexBuffer[i], sizeof(MIDIHDR));
      delete [] data->sysexBuffer[i]->lpData;
      delete [] data->sysexBuffer[i];
      if ( result != MMSYSERR_NOERROR ) {
        midiInClose( data->inHandle );
        errorString_ = "RtMidiIn::openPort: error closing Windows MM MIDI input port (midiInUnprepareHeader).";
        error( RtError::DRIVER_ERROR );
      }
    }

    midiInClose( data->inHandle );
    connected_ = false;
  }
}
Example #21
0
/*
 * assume midi is non-null (checked by caller)
 */
static PmError winmm_in_close(PmInternal *midi)
{
    midiwinmm_type m = (midiwinmm_type) midi->descriptor;
    if (!m) return pmBadPtr;
    /* device to close */
    if (pm_hosterror = midiInStop(m->handle.in)) {
        midiInReset(m->handle.in); /* try to reset and close port */
        midiInClose(m->handle.in);
    } else if (pm_hosterror = midiInReset(m->handle.in)) {
        midiInClose(m->handle.in); /* best effort to close midi port */
    } else {
        pm_hosterror = midiInClose(m->handle.in);
    }
    midi->descriptor = NULL;
    pm_free(m); /* delete */
    if (pm_hosterror) {
        int err = midiInGetErrorText(pm_hosterror, (char *) pm_hosterror_text, 
                                     PM_HOST_ERROR_MSG_LEN);
        assert(err == MMSYSERR_NOERROR);
        return pmHostError;
    }
    return pmNoError;
}
Example #22
0
void JackWinMMEDriver::CloseInput(MidiSlot* slot)
{
    MMRESULT res;
    int retry = 0;

    if (slot->fHandle == 0)
        return;

    HMIDIIN handle = (HMIDIIN)slot->fHandle;
    slot->fHeader->dwUser = 0;
    res = midiInStop(handle);
    if (res != MMSYSERR_NOERROR) {
        jack_error("midiInStop error");
    }
    res = midiInReset(handle);
    if (res != MMSYSERR_NOERROR) {
        jack_error("midiInReset error");
    }
    res = midiInUnprepareHeader(handle, slot->fHeader, sizeof(MIDIHDR));
    if (res != MMSYSERR_NOERROR) {
        jack_error("midiInUnprepareHeader error");
    }
    do {
        res = midiInClose(handle);
        if (res != MMSYSERR_NOERROR) {
            jack_error("midiInClose error");
        }
        if (res == MIDIERR_STILLPLAYING)
            midiInReset(handle);
        Sleep (10);
        retry++;
    } while ((res == MIDIERR_STILLPLAYING) && (retry < 10));

    if (slot->fHeader) {
        GlobalFreePtr(slot->fHeader);
    }
}
void CALLBACK midi_in_handler(HMIDIIN midi_in, UINT msg_type, DWORD user_data, DWORD midi_msg, DWORD param2)
{
	if (msg_type == MIM_DATA)
	{
		union
		{
			DWORD dwData;
			BYTE bData[4];
		}
		u;

		u.dwData = midi_msg;

		switch (u.bData[0] & 0xF0)
		{
			case 0x80:
			{
				key[u.bData[1]].is_pressed = 0;
				break;
			}
			case 0x90:
			{
				switch (state)
				{
					case STATE_PLAY:
					{
						break;
					}
					case STATE_CHOOSE_KEY_TO_EDIT:
					{
						key_to_edit = u.bData[1];
						break;
					}
					case STATE_CHOOSE_OUTPUT_NOTE:
					{
						key_data[key_to_edit].output_channel = u.bData[0] & 0x0F;
						key_data[key_to_edit].output_note = u.bData[1];
						key_data[key_to_edit].output_velocity = u.bData[2];
						break;
					}
					case STATE_CHOOSE_PATTERN:
					{
						if ((u.bData[1] >= 60) && (u.bData[1] < 72))
						{
							key_data[key_to_edit].pattern[u.bData[1] - 60] = 1;
						}

						break;
					}
				}

				key[u.bData[1]].is_pressed = 1;
				break;
			}
			case 0xB0:
			{
				switch (u.bData[1])
				{
					case 1:
					case 64:
					{
						if ((last_controller_value < 64) && (u.bData[2] >= 64))
						{
							switch (state)
							{
								case STATE_PLAY:
								{
									key_to_edit = -1;
									state = STATE_CHOOSE_KEY_TO_EDIT:
									break;
								}
								case STATE_CHOOSE_KEY_TO_EDIT:
								{
									if (key_to_edit == -1)
									{
										state = STATE_PLAY;
									}
									else
									{
										int i;
										key_data[key_to_edit].output_channel = -1;
										key_data[key_to_edit].output_note = -1;
										key_data[key_to_edit].output_velocity = -1;
										for (i = 0; i < 12; i++) key_data[key_to_edit].pattern[i] = 0;
										state = STATE_CHOOSE_OUTPUT_NOTE:
									}

									break;
								}
								case STATE_CHOOSE_OUTPUT_NOTE:
								{
									if (key_data[key_to_edit].output_channel == -1)
									{
										state = STATE_PLAY;
									}
									else
									{
										state = STATE_CHOOSE_PATTERN:
									}

									break;
								}
								case STATE_CHOOSE_PATTERN_STEPS:
								{
									state = PLAY:
									break;
								}
							}
						}

						last_controller_value = u.bData[2];
						break;
					}
					default:
					{
						break;
					}
				}

				break;
			}
			default:
			{
				break;
			}
		}
	}
}

BOOL WINAPI control_handler(DWORD control_type)
{
	midiInStop(midi_in);
	midiInClose(midi_in);
	midiOutClose(midi_out);
	return FALSE;
}

int main(int argc, char **argv)
{
	int i, j;
	int midi_in_number = 0;
	int midi_out_number = MIDI_MAPPER;

	for (i = 1; i < argc; i++)
	{
		if (strcmp(argv[i], "--in") == 0)
		{
			if (++i >= argc) break;
			sscanf(argv[i], "%d", &midi_in_number);
		}
		else if (strcmp(argv[i], "--out") == 0)
		{
			if (++i >= argc) break;
			sscanf(argv[i], "%d", &midi_out_number);
		}
		else
		{
			printf("Usage: %s [--in <n>] [--out <n>]\n", argv[0]);
			return 1;
		}
	}

	if (midiInOpen(&midi_in, midi_in_number, (DWORD)(midi_in_handler), (DWORD)(NULL), CALLBACK_FUNCTION) != MMSYSERR_NOERROR)
	{
		printf("Cannot open MIDI input port #%d.\n", midi_in_number);
		return 1;
	}

	if (midiOutOpen(&midi_out, midi_out_number, 0, 0, 0) != MMSYSERR_NOERROR)
	{
		printf("Cannot open MIDI output port #%d.\n", midi_out_number);
		return 1;
	}

	for (i = 0; i < 128; i++)
	{
		key_data[i].output_channel = -1;
		key_data[i].output_note = -1;
		key_data[i].output_velocity = -1;
		for (j = 0; j < 12; j++) key_data[i].pattern[j] = 0;
		key_data[i].is_pressed = 0;
	}

	SetConsoleCtrlHandler(control_handler, TRUE);

	midiInStart(midi_in);

	beat_start_time = now();

	while (1)
	{
		now = now();
		beat_duration = 60 / tempo;

		if (state == STATE_PLAY)
		{
			for (i = 0; i < 128; i++)
			{
				if (key_data[i].number_of_steps_in_pattern > 0)
				{
				}
			}
		}

		Sleep(CLOCK_RATE);
	}

	return 0;
}