Click here to Skip to main content
15,881,248 members
Articles / Desktop Programming / MFC

SDI (Sound Device Interface)--A library for Auditory Display

Rate me:
Please Sign up or sign in to vote.
4.60/5 (3 votes)
2 May 20046 min read 110.2K   3.7K   45  
A GDI-like API for 3D positioning of speech, and MIDI composition using a single string.
/******************************************************************************
SDI 1.0
    A library for Auditory Display
Copyright 2004 Dong Lin

This file is part of SDI.

    SDI is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    SDI is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with SDI; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

Last Updated : Apr.15th, 2004

For any question, suggestion or failure report, please contact me by:
e-mail: jonathan1983@126.com
*******************************************************************************/
/******************************************************************

File Name: utillib.cpp

Description:
	Implementation of link operation functions.
Note:


********************************************************************/

#include "Stdafx.h"
#include "utillib.h"

//////////////////////////////////////////////////////////////////////
BOOL listAddAfter(LISTHEADER* pCur, LISTHEADER* pNew)
{
	if(pCur==NULL || pNew==NULL)
		return FALSE;
	LISTHEADER* p;
	p=pCur->pNext;
	pCur->pNext=pNew;
	pNew->pNext=p;		// NULL, if pCur is at the tail
	pNew->pPrev=pCur;
	if(p != NULL)
		p->pPrev=pNew;
	return TRUE;
}

BOOL listAddBefore(LISTHEADER* pCur, LISTHEADER* pNew)
{
	if(pCur==NULL || pNew==NULL)
		return FALSE;
	LISTHEADER* p;
	p=pCur->pPrev;
	pCur->pPrev=pNew;
	pNew->pNext=pCur;
	pNew->pPrev=p;
	if(p != NULL)
		p->pNext=pNew;
	return TRUE;
}

BOOL listRemoveItem(LISTHEADER* pRemove)
{
	if(pRemove==NULL)
		return FALSE;
	if(pRemove->pPrev != NULL)	// Not Removing the head
		pRemove->pPrev->pNext=pRemove->pNext;
	if(pRemove->pNext != NULL)	// Not Removing the tail
		pRemove->pNext->pPrev=pRemove->pPrev;
	listInitHead(pRemove);
	return TRUE;
}

///////////////////////////////////////////////////////////////////
BOOL listInitHead(LISTHEADER* pHead)
{
	if(pHead==NULL)
		return FALSE;
	pHead->pNext=pHead->pPrev=NULL;
	return TRUE;
}

BOOL listDestroy(LISTHEADER* pHead)
{
	return TRUE;
}

//////////////////////////////////////////////////////////////////
BOOL listAddTail(LISTHEADER* pHead, LISTHEADER* pNew)
{
	if(pHead==NULL || pNew==NULL)
		return FALSE;
	LISTHEADER* p=pHead;
	while(NULL != p->pNext)
		p=p->pNext;
	listAddAfter(p,pNew);
	return TRUE;
}

LISTHEADER* listRemoveTail(LISTHEADER* pHead)
{
	if(pHead==NULL)
		return NULL;
	LISTHEADER *p=pHead, *t;
	while(p->pNext != NULL)
		p=p->pNext;
	t=p->pPrev;
	listRemoveItem(p);
	return t;
}
//////////////////////////////////////////////////////////////////

BOOL listAddHead(LISTHEADER* pHead, LISTHEADER* pNew)
{
	return listAddBefore(pHead,pNew);
}

LISTHEADER* listRemoveHead(LISTHEADER* pHead)
{
	LISTHEADER* p=pHead->pNext;
	listRemoveItem(pHead);
	return p;
}

///////////////////////////////////////////////////////////////////
ULONG listGetCount(LISTHEADER* pHead)
{
	if(pHead == NULL)
		return 0;
	LISTHEADER* p=pHead;
	ULONG n=0;
	while(p=p->pNext)
		n++;
	return n;
}

ULONG listGetIndexHead(LISTHEADER* pItem)
{
	ULONG n=0;
	LISTHEADER* p=pItem;
	while(p->pPrev != NULL)
	{
		p=p->pPrev;
		n++;
	}
	return n;
}
ULONG listGetIndexTail(LISTHEADER* pItem)
{
	ULONG n=0;
	LISTHEADER* p=pItem;
	while(p->pNext != NULL)
	{
		p=p->pNext;
		n++;
	}
	return n;
}

LISTHEADER* listGetHead(LISTHEADER* pItem)
{
	LISTHEADER* p=pItem;
	while(p->pPrev != NULL)
		p=p->pPrev;
	return p;
}

LISTHEADER* listGetTail(LISTHEADER* pItem)
{
	LISTHEADER* p=pItem;
	while(p->pNext != NULL)
		p=p->pNext;
	return p;
}

LISTHEADER* listGetItem(LISTHEADER* pHead, ULONG nIndex)
{
	ULONG n=0;
	LISTHEADER* p=pHead;
	while(p->pNext != NULL)
	{
		if(n==nIndex)
			break;
		p=p->pNext;
		n++;
	}
	return p;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Engineer
China China
A student at Zhejiang University, Zhejiang, China.
Major in Automation.
Now I want to study machine vision and robotics, but I'm really consumed with choices between hardware and software, and between research and engineering.
I'll be glad if you can give some suggestions.

Comments and Discussions