Example #1
0
static void CALLBACK MidiOutProc(HMIDIOUT hMidiOut, UINT wMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
{
	MFDevice *pDevice = (MFDevice*)dwInstance;
	MFMidiPC_MidiOutputDevice *pMidi = (MFMidiPC_MidiOutputDevice*)pDevice->pInternal;

	switch (wMsg)
	{
		case MOM_OPEN:
			MFDebug_Log(0, MFStr("Opened MIDI output device: %s", pDevice->strings[MFDS_ID]));
			break;
		case MOM_CLOSE:
			MFDebug_Log(0, MFStr("Opened MIDI output device: %s", pDevice->strings[MFDS_ID]));
			break;
		case MOM_DONE:
		{
			MIDIHDR *pHdr = (MIDIHDR*)dwParam1;
			MMRESULT r = midiOutUnprepareHeader(pMidi->hMidiOut, pHdr, sizeof(*pHdr));
			if (r != MMSYSERR_NOERROR)
			{
				wchar_t errorBuffer[256];
				midiOutGetErrorText(r, errorBuffer, sizeof(errorBuffer));
				MFDebug_Warn(1, MFStr("Failed to cleanup MIDI message: %s", MFString_WCharAsUTF8(errorBuffer)));
			}
			// TODO: return to pool...
			break;
		}
		case MOM_POSITIONCB:
			MFDebug_Log(0, "MIDI output device: Position CB");
			break;
	}
}
Example #2
0
char* ReadMaterialChunk(char *pFilePtr, char *pToken)
{
	if(!MFString_CaseCmp(pToken, "*MATERIAL_COUNT"))
	{
		int count;

		pFilePtr = GetInt(pFilePtr, &count);

		pModel->GetMaterialChunk()->materials.resize(count);

		MFDebug_Log(4, MFStr("Found %d materials.", count));
	}
	else if(!MFString_CaseCmp(pToken, "*MATERIAL"))
	{
		int matID;

		pFilePtr = GetInt(pFilePtr, &matID);

		pMaterial = &pModel->GetMaterialChunk()->materials[matID];

		pFilePtr = ProcessBlock(pFilePtr, "*MATERIAL", ReadMaterial);
	}
	else
	{
		MFDebug_Warn(3, MFStr("Unknown token: %s", pToken));
	}

	return pFilePtr;
}
Example #3
0
void MFPoolHeap::Dump() const
{
	MFDebug_Log(2, MFStr("Count %d, Used %d, Item Size %d bytes\n", numItems, numUsed, itemSize));
/*
	char *pEntry = (char*)pStorage;
	for(int i = 0; i < numItems; ++i)
	{
		bool bUsed = true;
		// check if it is in the free list
		void **pFree = pFreeList;
		while(pFree != NULL)
		{
			if(pEntry == (char*)pFree)
			{
				bUsed = false;
				pFree = NULL;
			}
			else
			{
				pFree = (void**)*pFree;
			}
		}

		if(bUsed)
			MFDebug_Log(MFStr("%d x \"%s\"\n", *(int*)pEntry, pEntry + sizeof(int)));

		pEntry += itemSize;
	}
*/
}
Example #4
0
void MFSound_InitModulePlatformSpecific(int *pSoundDataSize, int *pVoiceDataSize)
{
	MFCALLSTACK;

	// we need to return the size of the internal structures so the platform independant
	// code can make the correct allocations..
	*pSoundDataSize = sizeof(MFSoundDataInternal);

	MFDebug_Log(2, "Initialising PortAudio driver.");

	// init portaudio
	Pa_Initialize();

	// choose the output device
	PaDeviceIndex device = Pa_GetDefaultOutputDevice();

	// HACK: try and find an ALSA device (default OSS sucks)
	PaHostApiIndex alsaAPI = Pa_HostApiTypeIdToHostApiIndex(paALSA);
	if(alsaAPI >= 0)
	{
		int numDevices = Pa_GetDeviceCount();
		for(int a=0; a<numDevices; ++a)
		{
			pDeviceInfo = Pa_GetDeviceInfo(a);
			if(pDeviceInfo->hostApi == alsaAPI)
			{
				device = a;
				break;
			}
		}
	}

	pDeviceInfo = Pa_GetDeviceInfo(device);
	pHostAPIInfo = Pa_GetHostApiInfo(pDeviceInfo->hostApi);

	MFDebug_Log(2, MFStr("PortAudio output: %s", pDeviceInfo->name));
	MFDebug_Log(2, MFStr("PortAudio host: %s", pHostAPIInfo->name));
	MFDebug_Log(2, MFStr("Sample rate: %g", (float)pDeviceInfo->defaultSampleRate));
	MFDebug_Log(2, MFStr("In/Out channels: %d/%d", pDeviceInfo->maxInputChannels, pDeviceInfo->maxOutputChannels));
	MFDebug_Log(2, MFStr("Input latency: %g-%g", (float)pDeviceInfo->defaultLowInputLatency, (float)pDeviceInfo->defaultHighInputLatency));
	MFDebug_Log(2, MFStr("Output latency: %g-%g", (float)pDeviceInfo->defaultLowOutputLatency, (float)pDeviceInfo->defaultHighOutputLatency));

	// create a very low latency audio output stream
	PaStreamParameters params;
	params.device = Pa_GetDefaultOutputDevice();
	params.channelCount = 2;
	params.sampleFormat = paInt16;
	params.suggestedLatency = 0.0167;
	params.hostApiSpecificStreamInfo = NULL;

	PaError error = Pa_OpenStream(&pPAStream, NULL, &params, pDeviceInfo->defaultSampleRate, paFramesPerBufferUnspecified, paPrimeOutputBuffersUsingStreamCallback, MFSound_MixCallback, NULL);

	if(error != paNoError)
		MFDebug_Log(2, MFStr("Error: %s", Pa_GetErrorText(error)));
	else
		Pa_StartStream(pPAStream);
}
Example #5
0
MF_API void MFString_Dump()
{
	MFString temp = MFString_GetStats();

	MFDebug_Log(1, "\n-------------------------------------------------------------------------------------------------------");
	MFDebug_Log(1, temp.CStr());

	// dump all strings...
	MFDebug_Log(1, "");

	int numStrings = stringPool.GetNumAllocated();
	for(int a=0; a<numStrings; ++a)
	{
		MFStringData *pString = (MFStringData*)stringPool.GetItem(a);
		MFDebug_Log(1, MFStr("%d refs, " MFFMT_SIZE_T "b: \"%s\"", pString->refCount, pString->allocated, pString->pMemory));
	}
}
Example #6
0
	virtual HRESULT STDMETHODCALLTYPE OnDeviceAdded(LPCWSTR pwstrDeviceId)
	{
		MFDebug_Log(2, MFStr("WASAPI: Device added: %S", pwstrDeviceId));
		char temp[128];
		MFString_CopyUTF16ToUTF8(temp, pwstrDeviceId);
		MFDevice *pDev = MFDevice_GetDeviceById(temp);
		if(!pDev)
			pDev = NewDevice(pwstrDeviceId);
		return S_OK;
	}
Example #7
0
MF_API bool MFMidi_OpenOutput(MFDevice *pDevice)
{
	MFDebug_Assert(pDevice->type == MFDT_MidiOutput, "Not a MIDI device!");

	if (pDevice->state == MFDevState_Ready)
	{
		MFDebug_Warn(1, "Midi output device already opened!");
		return false;
	}
	if (pDevice->state != MFDevState_Available)
	{
		MFDebug_Warn(1, "Unable to open midi output device!");
		return false;
	}

	MFMidiPC_MidiOutputDevice *pMidi = (MFMidiPC_MidiOutputDevice*)pDevice->pInternal;

	// find and open the device
	// TODO: FIXME! this won't work if there are 2 instances of the same device attached to the PC!!!
	UINT numOutputDevices = midiOutGetNumDevs();
	UINT i = 0;
	for (; i < numOutputDevices; ++i)
	{
		MIDIOUTCAPS caps;
		MMRESULT r = midiOutGetDevCaps(i, &caps, sizeof(caps));
		if (r != MMSYSERR_NOERROR)
			continue;

		if (caps.wMid == pMidi->mid && caps.wPid == pMidi->pid)
			break;
	}
	if (i == numOutputDevices)
	{
		MFDebug_Log(0, MFStr("Midi output device '%s' not found!", pDevice->strings[MFDS_ID]));
		pDevice->state = MFDevState_Unknown; // set this flag?
		return false;
	}

	MMRESULT r = midiOutOpen(&pMidi->hMidiOut, i, (DWORD_PTR)MidiOutProc, (DWORD_PTR)pDevice, CALLBACK_FUNCTION);
	if (r != MMSYSERR_NOERROR)
	{
		pMidi->hMidiOut = NULL;
		pDevice->state = MFDevState_Unknown;

		wchar_t errorBuffer[256];
		midiOutGetErrorText(r, errorBuffer, sizeof(errorBuffer));
		MFDebug_Warn(1, MFStr("Failed to open MIDI output device: %s", MFString_WCharAsUTF8(errorBuffer)));

		return false;
	}

	pDevice->state = MFDevState_Ready;

	return true;
}
Example #8
0
static Context *CreateContext(MFDevice *pDevice)
{
	AudioDevice &device = *(AudioDevice*)pDevice->pInternal;

	if(!device.pDevice)
		device.pDevice = alcOpenDevice(pDevice->strings[MFDS_ID]);
	if(!device.pDevice)
		return NULL;

	Context *pContext = (Context*)MFHeap_Alloc(sizeof(Context));
	pContext->pContext = alcCreateContext(device.pDevice, NULL);
	pContext->pDevice = pDevice;
	pContext->pRender = &device;

	Context *pOld = MakeCurrent(pContext);

	const char *pVersion = alGetString(AL_VERSION);
	const char *pExtensions = alGetString(AL_EXTENSIONS);
	MFDebug_Log(0, MFStr("OpenAL Version: %s", pVersion));
	MFDebug_Log(0, MFStr("OpenAL Extensions: %s", pExtensions));

	pContext->ext.static_buffer = alIsExtensionPresent("ALC_EXT_STATIC_BUFFER") == AL_TRUE;
	pContext->ext.offset = alIsExtensionPresent("AL_EXT_OFFSET") == AL_TRUE;
	pContext->ext.float32 = alIsExtensionPresent("AL_EXT_float32") == AL_TRUE;
	pContext->ext.source_radius = alIsExtensionPresent("AL_EXT_SOURCE_RADIUS") == AL_TRUE;
	pContext->ext.buffer_sub_data = alIsExtensionPresent("AL_SOFT_buffer_sub_data") == AL_TRUE;
	pContext->ext.buffer_samples = alIsExtensionPresent("AL_SOFT_buffer_samples") == AL_TRUE;

	if(pContext->ext.static_buffer)
		alBufferDataStatic = (PFNALBUFFERDATASTATICPROC)alGetProcAddress("alBufferDataStatic");
	if(pContext->ext.buffer_sub_data)
		alBufferSubDataSOFT = (PFNALBUFFERSUBDATASOFTPROC)alGetProcAddress("alBufferSubDataSOFT");

	alListener3f(AL_POSITION, 0, 0, 0);
	alListener3f(AL_VELOCITY, 0, 0, 0);
	alListener3f(AL_ORIENTATION, 0, 0, -1);

	MakeCurrent(pOld);

	return pContext;
}
Example #9
0
	virtual HRESULT STDMETHODCALLTYPE OnDeviceRemoved(LPCWSTR pwstrDeviceId)
	{
		MFDebug_Log(2, MFStr("WASAPI: Device removed: %S", pwstrDeviceId));
		char temp[128];
		MFString_CopyUTF16ToUTF8(temp, pwstrDeviceId);
		MFDevice *pDev = MFDevice_GetDeviceById(temp);
		if(!pDev)
			pDev = NewDevice(pwstrDeviceId);
		if(pDev)
			UpdateState(pDev, DEVICE_STATE_UNPLUGGED);
		return S_OK;
	}
Example #10
0
	virtual HRESULT STDMETHODCALLTYPE OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState)
	{
		MFDebug_Log(2, MFStr("WASAPI: State changed: %d (%S)", dwNewState, pwstrDeviceId));
		char temp[128];
		MFString_CopyUTF16ToUTF8(temp, pwstrDeviceId);
		MFDevice *pDev = MFDevice_GetDeviceById(temp);
		if(!pDev)
			pDev = NewDevice(pwstrDeviceId);
		if(pDev)
			UpdateState(pDev, dwNewState);
		return S_OK;
	}
Example #11
0
	virtual HRESULT STDMETHODCALLTYPE OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR pwstrDefaultDeviceId)
	{
		MFDebug_Log(2, MFStr("WASAPI: Default device changed: %S", pwstrDefaultDeviceId));
		char temp[128];
		MFString_CopyUTF16ToUTF8(temp, pwstrDefaultDeviceId);
		MFDevice *pDev = MFDevice_GetDeviceById(temp);
		if(!pDev)
			pDev = NewDevice(pwstrDefaultDeviceId);
		if(pDev)
			MFDevice_SetDefaultDevice(gDt[flow], gDef[role], pDev);
		return S_OK;
	}
Example #12
0
// open a file from the mounted filesystem stack
MF_API MFFile* MFFileSystem_Open(const char *pFilename, uint32 openFlags)
{
	MFDebug_Log(5, MFStr("Call: MFFileSystem_Open(\"%s\", 0x%x)", pFilename, openFlags));

	GET_MODULE_DATA(MFFileSystemState);

	MFMount *pMount = pModuleData->pMountList;
	const char *pMountpoint = NULL;

	// search for a mountpoint
	size_t len = MFString_Length(pFilename);
	for(size_t a=0; a<len; a++)
	{
		if(pFilename[a] == ':')
		{
			pMountpoint = MFStrN(pFilename, a);
			pFilename += a+1;
			break;
		}

		if(pFilename[a] == '.')
		{
			// if we have found a dot, this cant be a mountpoint
			// (mountpoints may only be alphanumeric)
			break;
		}
	}

	// search for file through the mount list...
	while(pMount)
	{
		int onlyexclusive = pMount->volumeInfo.flags & MFMF_OnlyAllowExclusiveAccess;

		if((!pMountpoint && !onlyexclusive) || (pMountpoint && !MFString_CaseCmp(pMountpoint, pMount->volumeInfo.pVolumeName)))
		{
			// open the file from a mount
			MFFile *hFile = pModuleData->ppFileSystemList[pMount->volumeInfo.fileSystem]->callbacks.FSOpen(pMount, pFilename, openFlags);

			if(hFile)
				return hFile;
		}

		pMount = pMount->pNext;
	}

	if(!(openFlags & MFOF_TryOpen))
		MFDebug_Warn(4, MFStr("MFFile_Open(\"%s\", 0x%x) - Failed to open file", pFilename, openFlags));

	return NULL;
}
Example #13
0
char* ReadSceneChunk(char *pFilePtr, char *pToken)
{
	if(!MFString_CaseCmp(pToken, "*SCENE_FILENAME"))
	{
		char *pName;

		pFilePtr = GetString(pFilePtr, &pName);

		if(MFString_Length(pName) > 255)
		{
			MFDebug_Warn(3, MFStr("Error: More than 256 characters in nodel name, \"%s\"", pName));
			return pFilePtr;
		}

		pModel->name = pName;

		MFDebug_Log(4, MFStr("Model: %s", pName));
	}
	else if(!MFString_CaseCmp(pToken, "*SCENE_FIRSTFRAME"))
	{

	}
	else if(!MFString_CaseCmp(pToken, "*SCENE_LASTFRAME"))
	{

	}
	else if(!MFString_CaseCmp(pToken, "*SCENE_FRAMESPEED"))
	{

	}
	else if(!MFString_CaseCmp(pToken, "*SCENE_TICKSPERFRAME"))
	{

	}
	else if(!MFString_CaseCmp(pToken, "*SCENE_BACKGROUND_STATIC"))
	{

	}
	else if(!MFString_CaseCmp(pToken, "*SCENE_AMBIENT_STATIC"))
	{

	}
	else
	{
		MFDebug_Warn(3, MFStr("Unknown token: %s", pToken));
	}

	return pFilePtr;
}
Example #14
0
MF_API size_t MFFileSystem_Save(const char *pFilename, const char *pBuffer, size_t size)
{
	MFDebug_Log(5, MFStr("Call: MFFileSystem_Save(\"%s\")", pFilename));

	size_t bytesWritten = 0;

	MFFile *hFile = MFFileSystem_Open(pFilename, MFOF_Write|MFOF_Truncate|MFOF_Binary|MFOF_CreateDirectory);
	if(hFile)
	{
		bytesWritten = MFFile_Write(hFile, pBuffer, size, false);

		MFFile_Close(hFile);
	}

	return bytesWritten;
}
Example #15
0
MFFileSystemHandle MFFileSystem_RegisterFileSystem(const char *pFilesystemName, MFFileSystemCallbacks *pCallbacks)
{
	MFDebug_Log(5, MFStr("Call: MFFileSystem_RegisterFileSystem(\"%s\")", pFilesystemName));

	GET_MODULE_DATA(MFFileSystemState);

	for(uint32 a=0; a<gDefaults.filesys.maxFileSystems; a++)
	{
		if(pModuleData->ppFileSystemList[a] == NULL)
		{
			MFDebug_Assert(pCallbacks->Open, "No Open function supplied.");
			MFDebug_Assert(pCallbacks->Close, "No Close function supplied.");
			MFDebug_Assert(pCallbacks->Read, "No Read function supplied.");
			MFDebug_Assert(pCallbacks->Write, "No Write function supplied.");
			MFDebug_Assert(pCallbacks->Seek, "No Seek function supplied.");

			MFFileSystem *pFS = pModuleData->gFileSystems.Create();
			MFZeroMemory(pFS, sizeof(MFFileSystem));
			MFString_Copy(pFS->name, pFilesystemName);
			MFCopyMemory(&pFS->callbacks, pCallbacks, sizeof(MFFileSystemCallbacks));
			pModuleData->ppFileSystemList[a] = pFS;

#if defined(USE_JOB_THREAD)
			pFS->ppJobQueue = (MFJob**)MFHeap_Alloc(sizeof(MFJob*)*MAX_JOBS);
			pFS->jobs.Init(MFStr("%s Job List", pFilesystemName), MAX_JOBS+2);
			pFS->readJob = 0;
			pFS->writeJob = 0;
			pFS->numJobs = MAX_JOBS;
			pFS->semaphore = MFThread_CreateSemaphore("Filesystem Semaphore", MAX_JOBS, 0);
			pFS->thread = MFThread_CreateThread(MFStr("%s Thread", pFilesystemName), MKFileJobThread, pFS, MFPriority_AboveNormal);
#endif

			if(pFS->callbacks.RegisterFS)
				pFS->callbacks.RegisterFS();

			return a;
		}
	}

	MFDebug_Assert(false, MFStr("Exceeded maximum of %d Filesystems. Modify 'gDefaults.filesys.maxFileSystems'.", gDefaults.filesys.maxFileSystems));

	return -1;
}
Example #16
0
// validate a block of memory. returns false if memory had been corrupted.
MF_API bool MFHeap_ValidateMemory(const void *pMemory)
{
	MFCALLSTACK;

	if(!pMemory)
		return true;

	MFAllocHeader *pHeader = GetAllocHeader(pMemory);
	if(!pHeader)
	{
		MFDebug_Warn(0, MFStr("Missing allocation header for allocation 0x%p.", pMemory));
		return false;
	}

#if defined(USE_PRE_MUNGWALL)
	if(MFMemCompare((const char*)pMemory - MFHeap_MungwallBytes, gLlawgnum, MFHeap_MungwallBytes) == 0)
#endif
	if(MFMemCompare((const char*)pMemory + pHeader->size, gMungwall, MFHeap_MungwallBytes) == 0)
		return true;

	MFDebug_Log(0, MFStr("%s(" MFFMT_SIZE_T ") : Corrupted mungwall detected in allocation 0x%p.", pHeader->pFile, pHeader->line, pMemory));
	return false;
}
Example #17
0
static void CALLBACK MidiInProc(HMIDIIN hMidiIn, UINT wMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
{
	MFDevice *pDevice = (MFDevice*)dwInstance;
	MFMidiPC_MidiInputDevice *pMidi = (MFMidiPC_MidiInputDevice*)pDevice->pInternal;

	switch(wMsg)
	{
		case MIM_OPEN:
			MFDebug_Log(0, MFStr("Opened MIDI input device: %s", pDevice->strings[MFDS_ID]));
			break;
		case MIM_CLOSE:
			MFDebug_Log(0, MFStr("Closed MIDI input device: %s", pDevice->strings[MFDS_ID]));
			break;
		case MIM_MOREDATA:
			MFDebug_Log(0, "MIDI message: MIM_MOREDATA");
			break;
		case MIM_DATA:
		{
			MFMidiEvent ev;
			MFMidi_DecodeShortMessage((uint32)dwParam1, &ev, (uint32)dwParam2);

			switch(ev.ev)
			{
				case MFMET_NoteOff:
					pMidi->channels[ev.channel].notes[ev.noteOff.note] = 0;
					break;
				case MFMET_NoteOn:
				case MFMET_NoteAftertouch:
					pMidi->channels[ev.channel].notes[ev.noteOn.note] = ev.noteOn.velocity;
					break;
				case MFMET_ControlChange:
					pMidi->channels[ev.channel].control[ev.controlChange.control] = ev.controlChange.value;
					break;
				case MFMET_ProgramChange:
					pMidi->channels[ev.channel].program = ev.programChange.program;
					break;
				case MFMET_ChannelAftertouch:
					// TODO: ... what is this?
					break;
				case MFMET_PitchBend:
					pMidi->channels[ev.channel].pitch = ev.pitchBend.value;
					break;
				default:
					MFDebug_Assert(false, "Why are we getting sys events?");
					break;
			}

			if (pMidi->bBuffered || pMidi->pEventCallback)
			{
				if (pMidi->bBuffered)
				{
					if (pMidi->numEvents >= pMidi->numAllocated)
					{
						pMidi->numAllocated *= 2;
						pMidi->pEvents = (MFMidiEvent*)MFHeap_Realloc(pMidi->pEvents, sizeof(MFMidiEvent)*pMidi->numAllocated);
					}

					pMidi->pEvents[pMidi->numEvents++] = ev;
				}
				if (pMidi->pEventCallback)
				{
					pMidi->pEventCallback(pDevice, &ev);
				}
			}
			break;
		}
		case MIM_LONGDATA:
		{
			MIDIHDR *pHdr = (MIDIHDR*)dwParam1;

			MFMidiEvent ev;
			MFMidi_DecodePacket((const uint8*)pHdr->lpData, pHdr->dwBytesRecorded, &ev, (uint32)dwParam2);

			if (pMidi->bBuffered || pMidi->pEventCallback)
			{
				if (pMidi->bBuffered)
				{
					if (pMidi->numEvents >= pMidi->numAllocated)
					{
						pMidi->numAllocated *= 2;
						pMidi->pEvents = (MFMidiEvent*)MFHeap_Realloc(pMidi->pEvents, sizeof(MFMidiEvent)*pMidi->numAllocated);
					}

					pMidi->pEvents[pMidi->numEvents++] = ev;
				}
				if (pMidi->pEventCallback)
				{
					pMidi->pEventCallback(pDevice, &ev);
				}
			}

			MMRESULT r = midiInAddBuffer(pMidi->hMidiIn, pHdr, sizeof(*pHdr));
			if (r != MMSYSERR_NOERROR)
			{
				wchar_t errorBuffer[256];
				midiInGetErrorText(r, errorBuffer, sizeof(errorBuffer));
				MFDebug_Warn(1, MFStr("Failed to open MIDI input device: %s", MFString_WCharAsUTF8(errorBuffer)));
			}
			break;
		}
		case MIM_ERROR:
		case MIM_LONGERROR:
		{
			MFDebug_Log(0, MFStr("MIDI input error: %d, 0x%08X : 0x%08X", wMsg, dwParam1, dwParam2));
			break;
		}
	}
}
Example #18
0
char* ReadMaterial(char *pFilePtr, char *pToken)
{
	if(!MFString_CaseCmp(pToken, "*MATERIAL_NAME"))
	{
		char *pName;

		pFilePtr = GetString(pFilePtr, &pName);

		if(MFString_Length(pName) > 63)
		{
			MFDebug_Warn(3, MFStr("Error: More than 64 characters in material name, \"%s\"", pName));
			return pFilePtr;
		}

		pMaterial->name = pName;

		MFDebug_Log(4, MFStr("Found material: \"%s\"", pName));
	}
	else if(!MFString_CaseCmp(pToken, "*MATERIAL_CLASS"))
	{

	}
	else if(!MFString_CaseCmp(pToken, "*MATERIAL_AMBIENT"))
	{
		pFilePtr = GetFloat(pFilePtr, &pMaterial->ambient.x);
		pFilePtr = GetFloat(pFilePtr, &pMaterial->ambient.y);
		pFilePtr = GetFloat(pFilePtr, &pMaterial->ambient.z);
		pMaterial->ambient.w = 1.0f;
	}
	else if(!MFString_CaseCmp(pToken, "*MATERIAL_DIFFUSE"))
	{
		pFilePtr = GetFloat(pFilePtr, &pMaterial->diffuse.x);
		pFilePtr = GetFloat(pFilePtr, &pMaterial->diffuse.y);
		pFilePtr = GetFloat(pFilePtr, &pMaterial->diffuse.z);
		pMaterial->diffuse.w = 1.0f;
	}
	else if(!MFString_CaseCmp(pToken, "*MATERIAL_SPECULAR"))
	{
		pFilePtr = GetFloat(pFilePtr, &pMaterial->specular.x);
		pFilePtr = GetFloat(pFilePtr, &pMaterial->specular.y);
		pFilePtr = GetFloat(pFilePtr, &pMaterial->specular.z);
		pMaterial->specular.w = 1.0f;
	}
	else if(!MFString_CaseCmp(pToken, "*MATERIAL_SHINE"))
	{
		pFilePtr = GetFloat(pFilePtr, &pMaterial->glossiness);
	}
	else if(!MFString_CaseCmp(pToken, "*MATERIAL_SHINESTRENGTH"))
	{
		pFilePtr = GetFloat(pFilePtr, &pMaterial->specularLevel);
	}
	else if(!MFString_CaseCmp(pToken, "*MATERIAL_TRANSPARENCY"))
	{
		pFilePtr = GetFloat(pFilePtr, &pMaterial->diffuse.w);
		pMaterial->diffuse.w = 1.0f - pMaterial->diffuse.w;
	}
	else if(!MFString_CaseCmp(pToken, "*MATERIAL_WIRESIZE"))
	{

	}
	else if(!MFString_CaseCmp(pToken, "*MATERIAL_SHADING"))
	{

	}
	else if(!MFString_CaseCmp(pToken, "*MATERIAL_XP_FALLOFF"))
	{

	}
	else if(!MFString_CaseCmp(pToken, "*MATERIAL_SELFILLUM"))
	{
		float selfIllum;
		pFilePtr = GetFloat(pFilePtr, &selfIllum);

		pMaterial->emissive = pMaterial->diffuse * selfIllum;
		pMaterial->emissive.w = 1.0f;
	}
	else if(!MFString_CaseCmp(pToken, "*MATERIAL_FALLOFF"))
	{

	}
	else if(!MFString_CaseCmp(pToken, "*MATERIAL_XP_TYPE"))
	{

	}
	else
	{
		MFDebug_Warn(3, MFStr("Unknown token: %s", pToken));
	}

	return pFilePtr;
}
Example #19
0
void MFSound_InitModulePlatformSpecific(int *pSoundDataSize, int *pVoiceDataSize)
{
	MFCALLSTACK;

	gDevices.Init(sizeof(AudioDevice), 8, 8);

	ALCint minor, major;
	alcGetIntegerv(NULL, ALC_MAJOR_VERSION, 1, &major);
	alcGetIntegerv(NULL, ALC_MINOR_VERSION, 1, &minor);
	gAPIVersion = major*100 + minor;

	bool bCanEnumerate, bHasCapture;
	if(gAPIVersion >= 101)
	{
		bCanEnumerate = true;
		bHasCapture = true;
	}
	else
	{
		bCanEnumerate = alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") == AL_TRUE;
		bHasCapture = alcIsExtensionPresent(NULL, "ALC_EXT_CAPTURE") == AL_TRUE;
	}

	if(bCanEnumerate)
	{
		const char *pDevices = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
		const char *pDefault = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
		while(pDevices && *pDevices)
		{
			bool bIsDefault = !MFString_Compare(pDevices, pDefault);
			MFDebug_Log(2, MFStr("OpenAL: found output device '%s'%s", pDevices, bIsDefault ? " (default)" : ""));

			MFDevice *pDevice = MFDevice_AllocDevice(MFDT_AudioRender, &DestroyDevice);
			pDevice->pInternal = gDevices.AllocAndZero();
			pDevice->state = MFDevState_Ready;

			AudioDevice &device = *(AudioDevice*)pDevice->pInternal;
			MFString_CopyN(pDevice->strings[MFDS_ID], pDevices, sizeof(pDevice->strings[MFDS_ID])-1);
			pDevice->strings[MFDS_ID][sizeof(pDevice->strings[MFDS_ID])-1] = 0;
			device.pDevice = NULL;

			if(bIsDefault)
					MFDevice_SetDefaultDevice(MFDT_AudioRender, MFDDT_All, pDevice);

			pDevices += MFString_Length(pDevices) + 1;
		}

		if(!MFDevice_GetDefaultDevice(MFDT_AudioRender, MFDDT_Default))
		{
			MFDebug_Warn(2, "OpenAL: No default output device?");

			// HACK: set it to the first one...
			MFDevice *pDevice = MFDevice_GetDeviceByIndex(MFDT_AudioRender, 0);
			MFDevice_SetDefaultDevice(MFDT_AudioRender, MFDDT_All, pDevice);
		}

		if(bHasCapture)
		{
			pDevices = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
			pDefault = alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
			while(pDevices && *pDevices)
			{
				bool bIsDefault = !MFString_Compare(pDevices, pDefault);
				MFDebug_Log(2, MFStr("OpenAL: found capture device '%s'%s", pDevices, bIsDefault ? " (default)" : ""));

				MFDevice *pDevice = MFDevice_AllocDevice(MFDT_AudioCapture, &DestroyDevice);
				pDevice->pInternal = gDevices.AllocAndZero();
				pDevice->state = MFDevState_Ready;

				AudioDevice &device = *(AudioDevice*)pDevice->pInternal;
				MFString_CopyN(pDevice->strings[MFDS_ID], pDevices, sizeof(pDevice->strings[MFDS_ID])-1);
				pDevice->strings[MFDS_ID][sizeof(pDevice->strings[MFDS_ID])-1] = 0;
				device.pDevice = NULL;

				if(bIsDefault)
					MFDevice_SetDefaultDevice(MFDT_AudioCapture, MFDDT_All, pDevice);

				pDevices += MFString_Length(pDevices) + 1;
			}

			if(!MFDevice_GetDefaultDevice(MFDT_AudioCapture, MFDDT_Default))
				MFDebug_Warn(2, "OpenAL: No default capture device?");
		}
	}

	// create a context
	Context *pContext = CreateContext(MFDevice_GetDefaultDevice(MFDT_AudioRender, MFDDT_Default));
	MakeCurrent(pContext);

	// we need to return the size of the internal structures so the platform independant
	// code can make the correct allocations..
	*pSoundDataSize = sizeof(MFSoundDataInternal);
	*pVoiceDataSize = sizeof(MFVoiceDataInternal);
}
Example #20
0
void ParseASEFile(char *pFilePtr, F3DFile *_pModel)
{
	pModel = _pModel;

	char *pEnd;
	char *pToken;

	int braceCount = 0;
	bool inQuote = false;

	while(*pFilePtr != 0)
	{
		while(!(*pFilePtr == '*' && !braceCount && !inQuote) && *pFilePtr != 0)
		{
			if(*pFilePtr == '\"') inQuote = !inQuote;
			if(!inQuote)
			{
				if(*pFilePtr == '{') braceCount++;
				if(*pFilePtr == '}') braceCount--;
			}
			pFilePtr++;
		}

		pEnd = pFilePtr;

		while(!MFIsWhite(*pEnd) && *pEnd != 0) pEnd++;

		pToken = (char*)MFStrN(pFilePtr, (int)(pEnd - pFilePtr));
		pFilePtr = pEnd;

		if(!MFString_CaseCmp(pToken, "*3DSMAX_ASCIIEXPORT"))
		{
			int version = 0;

			pFilePtr = GetInt(pFilePtr, &version);

			MFDebug_Log(4, MFStr("Recognised .ASE file version: %d\n", version));
		}
		else if(!MFString_CaseCmp(pToken, "*COMMENT"))
		{
			char *pComment;

			pFilePtr = GetString(pFilePtr, &pComment);

			MFDebug_Log(4, MFStr("Comment: %s", pComment));
		}
		else if(!MFString_CaseCmp(pToken, "*SCENE"))
		{
			pFilePtr = ProcessBlock(pFilePtr, "*SCENE", ReadSceneChunk);
		}
		else if(!MFString_CaseCmp(pToken, "*MATERIAL_LIST"))
		{
			pFilePtr = ProcessBlock(pFilePtr, "*MATERIAL_LIST", ReadMaterialChunk);
		}
		else if(!MFString_CaseCmp(pToken, "*GEOMOBJECT"))
		{
			pFilePtr = ProcessBlock(pFilePtr, "*GEOMOBJECT", ReadGeomChunk);
		}
		else
		{
			MFDebug_Warn(3, MFStr("Unknown token: %s", pToken));
		}
	}
}
Example #21
0
void MFMidi_InitModulePlatformSpecific()
{
	UINT numInputDevices = midiInGetNumDevs();
	for (UINT i = 0; i < numInputDevices; ++i)
	{
		MIDIINCAPS caps;
		MMRESULT r = midiInGetDevCaps(i, &caps, sizeof(caps));
		if (r != MMSYSERR_NOERROR)
		{
			wchar_t errorBuffer[256];
			midiOutGetErrorText(r, errorBuffer, sizeof(errorBuffer));
			MFDebug_Warn(1, MFStr("Failed to query midi input device: %s", MFString_WCharAsUTF8(errorBuffer)));
			continue;
		}

		MFDevice *pDevice = MFDevice_AllocDevice(MFDT_MidiInput, &DestroyInputDevice);
		pDevice->pInternal = MFHeap_AllocAndZero(sizeof(MFMidiPC_MidiInputDevice));
		pDevice->state = MFDevState_Available;

		MFMidiPC_MidiOutputDevice *pDev = (MFMidiPC_MidiOutputDevice*)pDevice->pInternal;
		pDev->mid = caps.wMid;
		pDev->pid = caps.wPid;

		MFString_CopyUTF16ToUTF8(pDevice->strings[MFDS_ID], caps.szPname);
		MFString_CopyUTF16ToUTF8(pDevice->strings[MFDS_DeviceName], caps.szPname);
		MFString_CopyUTF16ToUTF8(pDevice->strings[MFDS_Description], caps.szPname);
		MFString_CopyUTF16ToUTF8(pDevice->strings[MFDS_InterfaceName], caps.szPname);
//		MFDS_Manufacturer

		MFDebug_Log(0, MFStr("Found midi input device: %s (%04X:%04X) - state: %d", pDevice->strings[MFDS_ID], caps.wMid, caps.wPid, pDevice->state));
	}

	UINT numOutputDevices = midiOutGetNumDevs();
	for (UINT i = 0; i < numOutputDevices; ++i)
	{
		MIDIOUTCAPS caps;
		MMRESULT r = midiOutGetDevCaps(i, &caps, sizeof(caps));
		if (r != MMSYSERR_NOERROR)
		{
			wchar_t errorBuffer[256];
			midiOutGetErrorText(r, errorBuffer, sizeof(errorBuffer));
			MFDebug_Warn(1, MFStr("Failed to query midi output device: %s", MFString_WCharAsUTF8(errorBuffer)));
			continue;
		}

		MFDevice *pDevice = MFDevice_AllocDevice(MFDT_MidiOutput, &DestroyOutputDevice);
		pDevice->pInternal = MFHeap_AllocAndZero(sizeof(MFMidiPC_MidiOutputDevice));
		pDevice->state = MFDevState_Available;

		MFMidiPC_MidiOutputDevice *pDev = (MFMidiPC_MidiOutputDevice*)pDevice->pInternal;
		pDev->mid = caps.wMid;
		pDev->pid = caps.wPid;

		MFString_CopyUTF16ToUTF8(pDevice->strings[MFDS_ID], caps.szPname);
		MFString_CopyUTF16ToUTF8(pDevice->strings[MFDS_DeviceName], caps.szPname);
		MFString_CopyUTF16ToUTF8(pDevice->strings[MFDS_Description], caps.szPname);
		MFString_CopyUTF16ToUTF8(pDevice->strings[MFDS_InterfaceName], caps.szPname);
//		MFDS_Manufacturer

		MFDebug_Log(0, MFStr("Found midi output device: %s (%04X:%04X) - state: %d", pDevice->strings[MFDS_ID], caps.wMid, caps.wPid, pDevice->state));
	}
}
Example #22
0
void MFInputLinux_InitGamepad(int fd, LinuxGamepad *pGamepad)
{
#if !defined(__CYGWIN__)
	MFCALLSTACK;

	pGamepad->joyFD = fd;

	// get the pad details
	ioctl(fd, JSIOCGNAME(80), pGamepad->identifier);
	ioctl(fd, JSIOCGAXES, &pGamepad->numAxiis);
	ioctl(fd, JSIOCGBUTTONS, &pGamepad->numButtons);

	MFGamepadInfo *pGI = pGamepadMappingRegistry;

	// we need to find a better way to get the VID/PID from the gamepad...
	if(!MFString_CompareN(pGamepad->identifier, "HID", 3))
	{
		// the device was unnamed, but it is a HID device, so we'll try and match the VID/PID
		char *pBase = pGamepad->identifier + 3, *pEnd;

		// get the VID string
		while(*pBase && !MFIsHex(*pBase))
			++pBase;

		pEnd = pBase + 1;
		while(MFIsHex(*pEnd))
			++pEnd;

		uint32 vid = MFHexToInt(MFStrN(pBase, pEnd - pBase));

		// get the PID string
		pBase = pEnd;
		while(*pBase && !MFIsHex(*pBase))
			++pBase;

		pEnd = pBase + 1;
		while(MFIsHex(*pEnd))
			++pEnd;

		uint32 pid = MFHexToInt(MFStrN(pBase, pEnd - pBase));

		// find a matching descriptor
		for(; pGI; pGI = pGI->pNext)
		{
			if(pGI->vendorID == vid && pGI->productID == pid)
				break;
		}
	}
	else
	{
		// the device is named, so we'll compare the name against our list and hope its the same as windows..
		// since we dont have the VID/PID though, we cant verify its not a device with an aliased name.
		pGI = pGI->pNext; // skip the first one
		for(; pGI; pGI = pGI->pNext)
		{
			// since linux appends the manufacturer name, we'll just check for a match on the end of the string
			int len1 = MFString_Length(pGamepad->identifier);
			int len2 = MFString_Length(pGI->pIdentifier);
			if(!MFString_Compare(pGamepad->identifier + (len1 - len2), pGI->pIdentifier))
				break;
		}
	}

	if(!pGI)
	{
		// use default descriptor
		pGamepad->pGamepadInfo = pGamepadMappingRegistry;
		MFDebug_Warn(1, MFStr("Found an unknown gamepad '%s', using default mappings.", pGamepad->identifier));

		// offer to send email detailing controller info..
//		MessageBox(NULL, "An unknown gamepad has been detected.\r\nWe strive to support every gamepad natively, please report your gamepad to Manu at [email protected].\r\nI will contact you and request a few details about the gamepad so it can be added to the registry for the next release.", "Unknown gamepad detected...", MB_OK);
	}
	else
	{
		// use applicable descriptor
		pGamepad->pGamepadInfo = pGI;
		MFDebug_Log(2, MFStr("Found gamepad: %s '%s'.", pGI->pName, pGI->pIdentifier));
	}
/*
	// fix up the linux mapping table
	const int *pButtonMap = pGamepad->pGamepadInfo->pButtonMap;
	int numAxiis = 0;

	for(int a=0; a<60; a++)
	{
		for(int b=0; b<GamepadType_Max; ++b)
		{
			if((pButtonMap[b] & AID_Analog) && MFGETAXIS(pButtonMap[b]) == a)
			{
				pGamepad->axisMap[a] = numAxiis;
				printf("%d = %d\n", a, numAxiis);
				++numAxiis;
			}
		}
	}
*/
#endif
}
Example #23
0
void MFSound_InitWASAPI()
{
	gDevices.Init(sizeof(MFAudioDevice), 8, 8);
	gCaptureDevices.Init(sizeof(MFAudioCaptureDevice), 8, 8);

	HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&gpEnumerator);
	if(FAILED(hr))
	{
		MFDebug_Assert(false, "Couldn't create multimedia device enumerator!");
		return;
	}

	// enumerate audio devices...
	gpNotification = new MFAudioDeviceNotification;
	gpEnumerator->RegisterEndpointNotificationCallback(gpNotification);

	// enumerate render devices
	IMMDeviceCollection *pDevices;
	gpEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE | DEVICE_STATE_UNPLUGGED, &pDevices);
	if(pDevices)
	{
		UINT count;
		pDevices->GetCount(&count);

		for(UINT i=0; i<count; ++i)
		{
			IMMDevice *pDevice;
			pDevices->Item(i, &pDevice);

			MFDevice *pDev = MFDevice_AllocDevice(MFDT_AudioRender, NULL);
			pDev->pInternal = gDevices.AllocAndZero();
			MFAudioDevice &device = *(MFAudioDevice*)pDev->pInternal;

			GetDeviceInfo(pDevice, pDev);

			pDevice->Release();

			MFDebug_Log(0, MFStr("Found audio device: %s, %s - state: %d (%s)", pDev->strings[MFDS_DeviceName], pDev->strings[MFDS_Manufacturer], device.state, pDev->strings[MFDS_ID]));
		}
		pDevices->Release();
	}

	// enumerate capture devices
	gpEnumerator->EnumAudioEndpoints(eCapture, DEVICE_STATE_ACTIVE | DEVICE_STATE_UNPLUGGED, &pDevices);
	if(pDevices)
	{
		UINT count;
		pDevices->GetCount(&count);

		for(UINT i=0; i<count; ++i)
		{
			IMMDevice *pDevice;
			pDevices->Item(i, &pDevice);

			MFDevice *pDev = MFDevice_AllocDevice(MFDT_AudioCapture, NULL);
			pDev->pInternal = gCaptureDevices.AllocAndZero();
			MFAudioCaptureDevice &device = *(MFAudioCaptureDevice*)pDev->pInternal;

			GetDeviceInfo(pDevice, pDev);

			pDevice->Release();

			MFDebug_Log(0, MFStr("Found audio capture device: %s, %s - state: %d (%s)", pDev->strings[MFDS_DeviceName], pDev->strings[MFDS_Manufacturer], device.state, pDev->strings[MFDS_ID]));
		}
		pDevices->Release();
	}

	// set defaults (this is some awkward windows code!)
	for(int i=0; i<2; ++i)
	{
		for(int j=0; j<3; ++j)
		{
			IMMDevice *pDevice;
			gpEnumerator->GetDefaultAudioEndpoint(gDirection[i], gRole[j], &pDevice);
			if(pDevice)
			{
				wchar_t *pDefaultId;
				pDevice->GetId(&pDefaultId);
				char temp[128];
				MFString_CopyUTF16ToUTF8(temp, pDefaultId);
				MFDevice *pDev = MFDevice_GetDeviceById(temp);
				MFDevice_SetDefaultDevice(gDt[i], gDef[j], pDev);
				CoTaskMemFree(pDefaultId);
				pDevice->Release();
			}
		}
	}
}
Example #24
0
	virtual HRESULT STDMETHODCALLTYPE OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key)
	{
		MFDebug_Log(3, MFStr("WASAPI: Property changed: %S", pwstrDeviceId));
		return S_OK;
	}
Example #25
0
int MFDisplay_CreateDisplay(int width, int height, int bpp, int rate, bool vsync, bool triplebuffer, bool wide, bool progressive)
{
	MFCALLSTACK;

	DWORD avPack = XGetAVPack();
	DWORD vidMode = XGetVideoStandard();
	DWORD vidFlags = XGetVideoFlags();

	// log the AV pack (just an FYI)
	switch(avPack)
	{
		case XC_AV_PACK_SCART:		MFDebug_Log(2, "MFDisplay: Video output using Scart AV Pack"); break;
		case XC_AV_PACK_HDTV:		MFDebug_Log(2, "MFDisplay: Video output using High Def Pack"); break;
		case XC_AV_PACK_RFU:		MFDebug_Log(2, "MFDisplay: Video output using RF Unit"); break;
		case XC_AV_PACK_SVIDEO:		MFDebug_Log(2, "MFDisplay: Video output using Advanced AV Pack"); break;
		case XC_AV_PACK_STANDARD:	MFDebug_Log(2, "MFDisplay: Video output using Standard AV Pack"); break;
		default:					MFDebug_Log(2, "MFDisplay: Video output using Unknown AV Pack"); break;
	}

	// calculate the frame buffer size and display mode from the dashboard info
	gbWidescreen = !!(vidFlags & (XC_VIDEO_FLAGS_WIDESCREEN));
	gbLetterBox = !!(vidFlags & (XC_VIDEO_FLAGS_LETTERBOX));
	wide = gbWidescreen;

	if(vidMode == XC_VIDEO_STANDARD_PAL_I)
	{
		// PAL modes (poor PAL users dont get high def) :(
		if(vidFlags & XC_VIDEO_FLAGS_PAL_60Hz)
		{
			width = 720;
			height = 480;
			rate = 60;
			progressive = false;
			MFDebug_Log(2, MFStr("MFDisplay: Video Mode set to PAL60%s", wide ? " (Widescreen)" : (gbLetterBox ? " (Letterbox)" : "")));
		}
		else
		{
			width = 720;
			height = 576;
			rate = 50;
			progressive = false;
			MFDebug_Log(2, MFStr("MFDisplay: Video Mode set to PAL (576i)%s", wide ? " (Widescreen)" : (gbLetterBox ? " (Letterbox)" : "")));
		}
	}
	else
	{
		// NTSC modes
		if(vidFlags & XC_VIDEO_FLAGS_HDTV_1080i)
		{
			width = 1920;
			height = 1080;
			rate = 60;
			progressive = false;
			MFDebug_Log(2, "MFDisplay: Video Mode set to 1080i");
		}
		else if(vidFlags & XC_VIDEO_FLAGS_HDTV_720p)
		{
			width = 1280;
			height = 720;
			rate = 60;
			progressive = true;
			MFDebug_Log(2, "MFDisplay: Video Mode set to 720p");
		}
		else if(vidFlags & XC_VIDEO_FLAGS_HDTV_480p)
		{
			width = 720;
			height = 480;
			rate = 60;
			progressive = true;
			MFDebug_Log(2, MFStr("MFDisplay: Video Mode set to 480p%s", wide ? " (Widescreen)" : (gbLetterBox ? " (Letterbox)" : "")));
		}
		else
		{
			width = 720;
			height = 480;
			rate = 60;
			progressive = false;
			MFDebug_Log(2, MFStr("MFDisplay: Video Mode set to NTSC (480i)%s", wide ? " (Widescreen)" : (gbLetterBox ? " (Letterbox)" : "")));
		}
	}

	// update display parameters
	gDisplay.fullscreenWidth = gDisplay.width = width;
	gDisplay.fullscreenHeight = gDisplay.height = height;
	gDisplay.progressive = progressive;
	gDisplay.refreshRate = rate;
	gDisplay.wide = wide;
	gDisplay.colourDepth = bpp;
	gDisplay.windowed = false;

	MFRenderer_CreateDisplay();

	// setup the initial viewport (letterbox)
	MFRenderer_ResetViewport();

	return 0;
}
Example #26
0
    void parse_error_handler(const char *what, void *where)
	{
		MFDebug_Log(1, "XML parse error:");
		MFDebug_Log(1, what);
	}