Ejemplo n.º 1
0
void SoundSystem::StopAllSounds( SoundObjectId _id, char *_eventName )
{
    for( int i = 0; i < m_sounds.Size(); ++i )
    {
        if( m_sounds.ValidIndex(i) )
        {
            SoundInstance *instance = m_sounds[i];
            
            if( instance->m_objId == _id )
            {                    
                if( !_eventName || stricmp(instance->m_eventName, _eventName) == 0 )
                {
                    if( instance->IsPlaying() )
                    {
                        instance->BeginRelease(true);
                    }
                    else
                    {
                        ShutdownSound( instance );
                    }
                }
            }
        }
    }
}
Ejemplo n.º 2
0
void SoundSystem::TriggerEvent( SoundObjectId _objId, char *_eventName )
{
    if( !m_channels ) return;

	START_PROFILE("TriggerEvent");
    
    char *objectType = m_interface->GetObjectType(_objId);
    if( objectType )
    {
        SoundEventBlueprint *seb = m_blueprints.GetBlueprint(objectType);
        if( seb )
        {
            for( int i = 0; i < seb->m_events.Size(); ++i )
            {
                SoundInstanceBlueprint *sib = seb->m_events[i];
                if( stricmp( sib->m_eventName, _eventName ) == 0 )
                {
                    Vector3<float> pos, vel;
                    m_interface->GetObjectPosition( _objId, pos, vel );

                    SoundInstance *instance = new SoundInstance();
                    instance->Copy( sib->m_instance );
                    instance->m_objIds.PutData( _objId );
                    instance->m_pos = pos;
                    instance->m_vel = vel;
                    bool success = InitialiseSound  ( instance );                
                    if( !success ) ShutdownSound    ( instance );                
                }
            }
        }
    }

	END_PROFILE("TriggerEvent");
}
Ejemplo n.º 3
0
void SoundSystem::TriggerEvent( char *_type, char *_eventName, Vector3<float> const &_pos )
{
    if( !m_channels ) return;

	START_PROFILE("TriggerEvent");
    
    SoundEventBlueprint *seb = m_blueprints.GetBlueprint(_type);
    if( seb )
    {
        for( int i = 0; i < seb->m_events.Size(); ++i )
        {
            SoundInstanceBlueprint *sib = seb->m_events[i];
            if( stricmp( sib->m_eventName, _eventName ) == 0 )
            {
                SoundInstance *instance = new SoundInstance();
                instance->Copy( sib->m_instance );
                instance->m_pos = _pos;
                bool success = InitialiseSound  ( instance );                
                if( !success ) ShutdownSound    ( instance );                
            }
        }
    }

	END_PROFILE("TriggerEvent");
}
Ejemplo n.º 4
0
void SoundTest::PlayStopEffect(PerfFuncData * data)
{
    SoundInstance * clickInst = sndClick->Play();
    TEST_VERIFY(clickInst->GetState() == SoundInstance::STATE_PLAYING);
    
    sndClick->Stop();
    TEST_VERIFY(clickInst->GetState() == SoundInstance::STATE_FORCED_STOPPED);
}
Ejemplo n.º 5
0
void SoundTest::PlayStopMusic(PerfFuncData * data)
{
    SoundInstance * musicInst = music->Play();
    TEST_VERIFY(musicInst->GetState() == SoundInstance::STATE_PLAYING);
    
    music->Stop();
    TEST_VERIFY(musicInst->GetState() == SoundInstance::STATE_FORCED_STOPPED);
}
Ejemplo n.º 6
0
	virtual SoundInstanceId play(SoundResource* sr, bool loop, float volume, const Vector3& pos)
	{
		SoundInstance instance;
		instance.create(sr, pos);
		SoundInstanceId id = id_array::create(m_playing_sounds, instance);
		id_array::get(m_playing_sounds, id).m_id = id;
		instance.play(loop, volume);
		return id;
	}
Ejemplo n.º 7
0
    void SoundPlayer::setVolume(float v)
    {
        _volume = v;
        for (playingSounds::iterator i = _sounds.begin(); i != _sounds.end(); ++i)
        {
            SoundInstance* s = (*i).get();
            s->setVolume(v);
        }

    }
Ejemplo n.º 8
0
void Button::playPressedSound()
{
	if(getEngine()->getSoundEnvironment() != NULL)
	{
		if(SystemManager::settingExists("config/sound"))
		{
			Sound* sound = getEngine()->getSoundEnvironment()->getSound("selectMenuSound");
			if( sound != NULL )
			{
				SoundInstance* inst = new SoundInstance(sound);
				inst->setLocalPosition( getContainer()->get3dSettings().position );
				inst->play();
			}
		}
	}
}
Ejemplo n.º 9
0
void SoundSystem::PropagateBlueprints( bool _forceRestart )
{
    for( int i = m_sounds.Size() - 1; i >= 0; --i )
    {
        if( m_sounds.ValidIndex(i) )
        {
            SoundInstance *instance = m_sounds[i];

			if( instance->IsPlayable() )
			{
				instance->PropagateBlueprints( _forceRestart );
			}
			else
			{
				ShutdownSound( instance );
			}
        }
    }
}
Ejemplo n.º 10
0
	virtual void initialize()
	{
		env = getEngine()->getSoundEnvironment();
		env->setAssetDirectory("/Users/evldemo/sounds/");
		
		// All sound files should be in .wav format
		// For positional sounds, file should be mono.
		// Rest of important sound code is in handleEvent()
		sound = env->loadSoundFromFile("beep", "/menu_sounds/menu_select.wav");
		music = env->loadSoundFromFile("music", "/music/filmic.wav");
		sound1 = env->loadSoundFromFile("tricorder", "/arthur/TOS-tricorder.wav");

		// playStereo() is for ambient music.
		// Currently available functions:
		//	 setVolume(float) - amplitude from (0.0 - 1.0)
		//	 setLoop(bool)
		//	 stop() - this means this instance is finished and a new
		//			  sound instance will need to be created to play
		SoundInstance* musicInst = new SoundInstance(music);
		musicInst->setVolume(0.2f);
		musicInst->playStereo();

		changeCubeColor = false;
	}
Ejemplo n.º 11
0
void SoundSystem::TriggerDuplicateSound ( SoundInstance *_instance )
{
    SoundInstance *newInstance = new SoundInstance();
    newInstance->Copy( _instance );
    newInstance->m_parent = _instance->m_parent;
    newInstance->m_pos = _instance->m_pos;
    newInstance->m_vel = _instance->m_vel;

    for( int i = 0; i < _instance->m_objIds.Size(); ++i )
    {
        SoundObjectId id = *_instance->m_objIds.GetPointer(i);
        newInstance->m_objIds.PutData( id );
    }

    bool success = InitialiseSound( newInstance );
    if( success && newInstance->m_positionType == SoundInstance::TypeInEditor )
    {
        m_editorInstanceId = newInstance->m_id;        
    }
    else if( !success )
    {
        ShutdownSound( newInstance);
    }
}
Ejemplo n.º 12
0
	SoundTest()
	{
		//soundManager = new SoundManager();
		//soundManager->connectToServer("localhost",57120);
		
		// More concise method of above two lines
		soundManager = new SoundManager("localhost",57120);

		soundManager->showDebugInfo(true);

		// Get default sound environment
		env = soundManager->getSoundEnvironment();

		
		while( !soundManager->isSoundServerRunning() )
		{
			soundManager->startSoundServer();
		}

		// Load sound assets
		//env->setAssetDirectory("menu_sounds");

		showMenuSound = env->loadSoundFromFile("showMenuSound","menu_sounds/menu_load.wav");
		hideMenuSound = env->loadSoundFromFile("hideMenuSound","menu_sounds/menu_closed.wav");
		scrollMenuSound = env->loadSoundFromFile("scrollMenuSound","menu_sounds/menu_scroll.wav");
		selectMenuSound = env->loadSoundFromFile("selectMenuSound","menu_sounds/menu_select.wav");
		soundLoop = env->loadSoundFromFile("mus","Omega4Relay.wav");

		SoundInstance* soundInstance = new SoundInstance(showMenuSound);
		soundInstance->setReverb( 1.0, 1.0 );
		soundInstance->setVolume(1.0);
		soundInstance->setPosition( Vector3f(0,1,0) );
		soundInstance->play();

		rewindingSoundInstance = new SoundInstance(showMenuSound);
	}
Ejemplo n.º 13
0
bool SoundSystem::SoundLibraryMainCallback( unsigned int _channel, signed short *_data, 
									        unsigned int _numSamples, int *_silenceRemaining )
{
    if( !g_soundSystem ) return false;

	SoundInstanceId soundId = g_soundSystem->m_channels[_channel];
    SoundInstance *instance = g_soundSystem->GetSoundInstance( soundId );
    bool stereo = g_soundSystem->IsMusicChannel(_channel);
    
    if( instance && instance->m_soundSampleHandle )
    {
		//
        // Fill the space with sample data

        float relFreq = g_soundLibrary3d->GetChannelRelFreq(_channel);
		int numSamplesWritten = instance->m_soundSampleHandle->Read( _data, _numSamples, stereo, relFreq);

        if( numSamplesWritten < _numSamples )
        {
            signed short *loopStart = _data + numSamplesWritten;
            unsigned int numSamplesRemaining = _numSamples - numSamplesWritten;
            
            if( instance->m_loopType == SoundInstance::Looped ||
                instance->m_loopType == SoundInstance::LoopedADSR )
            {
                while( numSamplesRemaining > 0 )
                {
                    bool looped = instance->AdvanceLoop();
                    if( looped )
                    {
                        unsigned int numWritten = instance->m_soundSampleHandle->Read( loopStart, numSamplesRemaining, stereo , relFreq);
                        loopStart += numWritten;
                        numSamplesRemaining -= numWritten;
                    }
                    else
                    {
                        g_soundLibrary3d->WriteSilence( loopStart, numSamplesRemaining );
                        numSamplesRemaining = 0;
                    }
                }
            }
            else if( instance->m_loopType == SoundInstance::SinglePlay)
            {
                if( numSamplesWritten > 0 )
                {
                    // The sound just came to an end, so write a whole buffers worth of silence
                    g_soundLibrary3d->WriteSilence( loopStart, numSamplesRemaining );
                    *_silenceRemaining = g_soundLibrary3d->GetChannelBufSize(_channel) - numSamplesRemaining;
                }
                else
                {
                    // The sound came to an end and now we are writing silence
                    g_soundLibrary3d->WriteSilence( loopStart, numSamplesRemaining );
                    *_silenceRemaining -= numSamplesRemaining;
                    if( *_silenceRemaining <= 0 )
                    {
                        instance->BeginRelease(false);
                    }
                }
            }
        }

		return true;
    }
    else
    {
        g_soundLibrary3d->WriteSilence( _data, _numSamples );
		return false;
    }
}
Ejemplo n.º 14
0
void HelloApplication::handleEvent(const Event& evt)
{
	if(evt.getServiceType() == Service::Wand)
	{
				
		xPos = evt.getPosition().x();
		yPos = evt.getPosition().y();
		zPos = evt.getPosition().z();
		
		if( soundLoopInst != NULL )
			soundLoopInst->setPosition( evt.getPosition() );
	
		if( evt.getType() == Event::Down )
		{
			if( evt.getFlags() == Event::Button3 ) // Wand cross button
			{
				// playStereo() is for ambient music.
				// Currently available functions:
				//	 setVolume(float) - amplitude from (0.0 - 1.0)
				//	 setLoop(bool)
				//	 stop() - this means this instance is finished and a new
				//			  sound instance will need to be created to play
				SoundInstance* musicInst = new SoundInstance(music);
				musicInst->setVolume(0.2f);
				musicInst->playStereo();
			}
			else if( evt.getFlags() == Event::Button5 ) // Wand L1
			{
				env->getSoundManager()->stopAllSounds();
			}
			else if( evt.getFlags() == Event::ButtonLeft ) // DPad
			{
				SoundInstance* soundInst = new SoundInstance(sound);
				soundInst->setPosition( evt.getPosition() );
				soundInst->play();
				changeCubeColor = true;
			}
			else if( evt.getFlags() == Event::ButtonRight ) // DPad
			{
				if( soundLoopInst != NULL || !soundLoopInst->isPlaying() )
				{
					// Positional sounds use play()
					// Currently available functions:
					//	 stop() - this means this instance is finished and a new
					//			  sound instance will need to be created to play
					//	 setPosition(Vector3f) 
					//	 setVolume(float) - amplitude from (0.0 - 1.0)
					//	 setLoop(bool)
					//	 setMix(float) - wetness of sound (0.0 - 1.0)
					//	 setReverb(float) - room size / reverb amount (0.0 - 1.0)
					//	 setWidth(int) - number of speakers to spread sound across (1-20)
					//			This will eventually be replaced with a sound radius
					soundLoopInst = new SoundInstance(sound1);
					soundLoopInst->setPosition( evt.getPosition() );
					soundLoopInst->setLoop(true);
					soundLoopInst->setVolume(0.2f);
					soundLoopInst->setWidth(3);
					soundLoopInst->play();
				}
				else if( soundLoopInst != NULL )
				{
					soundLoopInst->stop();
				}
				
				changeCubeColor = true;
			}
			else
			{
				SoundInstance* soundInst = new SoundInstance(sound);
				soundInst->setPosition( evt.getPosition() );
				soundInst->setRoomSize(1.0);
				soundInst->setWetness(1.0);
				//soundInst->setVolume(0.5);
				soundInst->play();
				changeCubeColor = true;
			}
			
			
		}
		else if( evt.getType() == Event::Up )
		{
			changeCubeColor = false;
		}
	}
}
Ejemplo n.º 15
0
 void SoundPlayer::_onSoundAboutDone(void* sound_instance, Channel* channel, const sound_desc& desc)
 {
     SoundInstance* t = (SoundInstance*)sound_instance;
     t->aboutDone();
 }
Ejemplo n.º 16
0
 void SoundPlayer::_onSoundDone(void* sound_instance, Channel* channel, const sound_desc& desc)
 {
     SoundInstance* t = (SoundInstance*)sound_instance;
     t->finished();
 }
Ejemplo n.º 17
0
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Checks the type of event. If a valid event, creates an event packet and returns true. Else return false.
	virtual bool handleEvent(const Event& evt)
	{
		
		float leftRightAnalog;
		float upDownAnalog;
		float zeroTolerence = 0.008f;
		float xPos;
		float yPos;
		float zPos;

		switch(evt.getServiceType())
		{
			case Service::Wand:
				leftRightAnalog = evt.getExtraDataFloat(0);
				upDownAnalog = evt.getExtraDataFloat(1);

				volume = evt.getExtraDataFloat(4);
				
				if( soundLoopInstance != NULL )
				{
					soundLoopInstance->setVolume(volume);
				}

				if( evt.getType() == Event::Down ){

					if( evt.getFlags() & Event::Button3){ // Cross
						
						soundLoopInstance->setEnvironmentSound( true );
						soundLoopInstance->setLoop( true );
						
						soundLoopInstance->playStereo();
					}
					if( evt.getFlags() & Event::Button2){ // Circle
						soundLoopInstance->stop();
					}
					
					if( evt.getFlags() & Event::Button5){ // L1
						soundLoopInstance = new SoundInstance(soundLoop);
					}

					if( evt.getFlags() & Event::ButtonRight){
						
						rewindingSoundInstance->setPosition( Vector3f(leftRightAnalog,1,0) );
						rewindingSoundInstance->setReverb( upDownAnalog, upDownAnalog );
						rewindingSoundInstance->play();
					}
					if( evt.getFlags() & Event::ButtonLeft){
						SoundInstance* soundInstance = new SoundInstance(hideMenuSound);
						soundInstance->setPosition( Vector3f(leftRightAnalog,1,0) );
						soundInstance->setReverb( upDownAnalog, upDownAnalog );
						soundInstance->play();
					}
					if( evt.getFlags() & Event::ButtonUp){
						SoundInstance* soundInstance = new SoundInstance(selectMenuSound);
						soundInstance->setPosition( Vector3f(leftRightAnalog,1,0) );
						soundInstance->setReverb( upDownAnalog, upDownAnalog );
						soundInstance->play();
					}
					if( evt.getFlags() & Event::ButtonDown){
						SoundInstance* soundInstance = new SoundInstance(scrollMenuSound);
						soundInstance->setPosition( Vector3f(leftRightAnalog,1,0) );
						soundInstance->setReverb( upDownAnalog, upDownAnalog );
						soundInstance->play();
					}
					//printf("%d \n", evt.getFlags() );
				}
				
				if( (leftRightAnalog > zeroTolerence || leftRightAnalog < -zeroTolerence) &&
					(upDownAnalog > zeroTolerence || upDownAnalog < -zeroTolerence)
					){
					position[0] = leftRightAnalog;
					position[1] = upDownAnalog;
					printf("Analog Stick: %f %f\n", position[0], position[1]);
				}
				if( volume > 0 )
					printf("Analog Trigger (L2): %f\n", volume);
				return true;
				break;

			case Service::Mocap:
				//if( evt.getSourceId() == 0 )
				//	soundManager->setListenerPosition( evt.getPosition() );
				//env->setListenerPosition( Vector3f(0,0,0) );
				//else if( instanceCreated && evt.getSourceId() == 1 )
				//	soundInstance->setPosition( evt.getPosition() );
				//printf("ID: %d Pos: %f %f %f\n", evt.getSourceId(), evt.getPosition(0), evt.getPosition(1), evt.getPosition(2) );
				break;
		}
		
		return false;
	}
Ejemplo n.º 18
0
void SoundSystem::Advance()
{
    if( !m_channels )
	{
		return;
	}

    float timeNow = GetHighResTime();
    if( timeNow >= m_timeSync )
    {
        m_timeSync = timeNow + SOUNDSYSTEM_UPDATEPERIOD;
        
        START_PROFILE("SoundSystem");        
		
#ifndef TARGET_MSVC
		((SoundLibrary2dSDL *)g_soundLibrary2d)->m_callbackLock.Lock();
#endif
		
        //
        // Resync with blueprints (changed by editor)

        START_PROFILE("Propagate Blueprints" );
        if( m_propagateBlueprints )
        {
            PropagateBlueprints();
        }
        END_PROFILE("Propagate Blueprints" );


        //
		// First pass : Recalculate all Perceived Sound Volumes
		// Throw away sounds that have had their chance
        // Build a list of instanceIDs for sorting

        START_PROFILE("Allocate Sorted Array" );
        static int sortedArraySize = 128;
        static SoundInstanceId *sortedIds = NULL;
        if( m_sounds.NumUsed() > sortedArraySize )
        {
            delete [] sortedIds;
            sortedIds = NULL;
            while( sortedArraySize < m_sounds.NumUsed() )
                sortedArraySize *= 2;
        }
        if( !sortedIds )
        {            
            sortedIds = new SoundInstanceId[ sortedArraySize ];
        }

        int numSortedIds = 0;
        END_PROFILE("Allocate Sorted Array" );

        START_PROFILE("Perceived Volumes" );
        for( int i = 0; i < m_sounds.Size(); ++i )
        {
            if( m_sounds.ValidIndex(i) )
            {
                SoundInstance *instance = m_sounds[i];
                if( !instance->IsPlaying() && !instance->m_loopType ) instance->m_restartAttempts--;
                if( instance->m_restartAttempts < 0 )
                {
                    ShutdownSound( instance );
                }
                else if( instance->m_positionType == SoundInstance::Type3DAttachedToObject &&
                         !instance->GetAttachedObject().IsValid() )                
                {
                    ShutdownSound( instance );
                }
                else
                {
                    instance->CalculatePerceivedVolume();
                    sortedIds[numSortedIds] = instance->m_id;
                    numSortedIds++;
                }
            }
        }
        END_PROFILE("Perceived Volumes" );


        //        
		// Sort sounds into perceived volume order
        // NOTE : There are exactly numSortedId elements in sortedIds.  
        // NOTE : It isn't safe to assume numSortedIds == m_sounds.NumUsed()
        
        START_PROFILE("Sort Samples" );
        qsort( sortedIds, numSortedIds, sizeof(SoundInstanceId), SoundInstanceCompare );
        END_PROFILE("Sort Samples" );


        //
		// Second pass : Recalculate all Sound Priorities starting with the nearest sounds
        // Reduce priorities as more of the same sounds are played

        BTree<float> existingInstances;
        
                
        //                
        // Also look out for the highest priority new sound to swap in

        START_PROFILE("Recalculate Priorities" );

        LList<SoundInstance *> newInstances;
        SoundInstance *newInstance = NULL;
        float highestInstancePriority = 0.0f;

        for( int i = 0; i < numSortedIds; ++i )
        {
            SoundInstanceId id = sortedIds[i];
            SoundInstance *instance = GetSoundInstance( id );
            AppDebugAssert( instance );

            instance->m_calculatedPriority = instance->m_perceivedVolume;

            BTree<float> *existingInstance = existingInstances.LookupTree( instance->m_eventName );
            if( existingInstance )
            {
                instance->m_calculatedPriority *= existingInstance->data;
                existingInstance->data *= 0.75f;
            }
            else
            {
                existingInstances.PutData( instance->m_eventName, 0.75f );
            }

            if( !instance->IsPlaying() )
            {
                if( instance->m_positionType == SoundInstance::TypeMusic )
                {
                    newInstances.PutData( instance );
                }
                else if( instance->m_calculatedPriority > highestInstancePriority )
                {
                    newInstance = instance;
                    highestInstancePriority = instance->m_calculatedPriority;
                }
            }
        }

        if( newInstance )
        {
            newInstances.PutData( newInstance );
        }

        END_PROFILE("Recalculate Priorities" );
        
     
        for( int i = 0; i < newInstances.Size(); ++i )
        {            
            SoundInstance *newInstance = newInstances[i];
            bool isMusic = (newInstance->m_positionType == SoundInstance::TypeMusic);

            // Find worst old sound to get rid of  
            START_PROFILE("Find best Channel" );
            int bestAvailableChannel = FindBestAvailableChannel( isMusic );
            END_PROFILE("Find best Channel" );

			// FindBestAvailableChannel can return -1, so let's not access an invalid index later on.
			if ( bestAvailableChannel < 0 )
				continue;

            START_PROFILE("Stop Old Sound" );
			// Stop the old sound
            SoundInstance *existingInstance = GetSoundInstance( m_channels[bestAvailableChannel] );
            if( existingInstance && !existingInstance->m_loopType )
            {
                ShutdownSound( existingInstance );
            }
            else if( existingInstance )
            {
                existingInstance->StopPlaying();
            }            
            END_PROFILE("Stop Old Sound" );


            START_PROFILE( "Start New Sound" );
			// Start the new sound
            bool success = newInstance->StartPlaying( bestAvailableChannel );
            if( success )
            {
                m_channels[bestAvailableChannel] = newInstance->m_id;
            }
            else
            {
                // This is fairly bad, the sound failed to play
                // Which means it failed to load, or to go into a channel
                ShutdownSound( newInstance );
            }
            END_PROFILE("Start New Sound" );
            
            START_PROFILE("Reset Channel" );
            g_soundLibrary3d->ResetChannel( bestAvailableChannel);
            END_PROFILE("Reset Channel" );
        }


        //
        // Advance all sound channels

        START_PROFILE("Advance All Channels" );
        for( int i = 0; i < m_numChannels; ++i )
        {            
            SoundInstanceId soundId = m_channels[i];            
            SoundInstance *currentSound = GetSoundInstance( soundId );                         
            if( currentSound )
            {
                bool amIDone = currentSound->Advance();
                if( amIDone )
                {                    
			        START_PROFILE("Shutdown Sound" );
                    ShutdownSound( currentSound );
			        END_PROFILE("Shutdown Sound" );
                }    
            }
        }
        END_PROFILE("Advance All Channels" );


		//
        // Update our listener position

        START_PROFILE("UpdateListener" );    

        Vector3<float> camPos, camVel, camUp, camFront;
        bool cameraDefined = m_interface->GetCameraPosition( camPos, camFront, camUp, camVel );

        if( cameraDefined )
        {
            if( g_preferences->GetInt("SoundSwapStereo",0) == 0 )
            {
                camUp *= -1.0f;
            }

            g_soundLibrary3d->SetListenerPosition( camPos, camFront, camUp, camVel );
        }
        
        END_PROFILE("UpdateListener" );    


        //
        // Advance our sound library

        START_PROFILE("SoundLibrary3d Advance" );
        g_soundLibrary3d->Advance();
        END_PROFILE("SoundLibrary3d Advance" );
      
#ifdef SOUNDSYSTEM_VERIFY
        RuntimeVerify();
#endif

#ifndef TARGET_MSVC
		((SoundLibrary2dSDL *)g_soundLibrary2d)->m_callbackLock.Unlock();
#endif

        END_PROFILE("SoundSystem");                    
    }
}
void SoundParameterGraph::HandleMouseEvents()
{
    if( EclMouseInButton(m_parent,this) )                    
    {
		bool lmb = g_inputManager->controlEvent( ControlEclipseLMousePressed );
        bool rmb = g_inputManager->controlEvent( ControlEclipseRMousePressed );

        float input, output;
        GetValues( g_target->X() - ( m_parent->m_x + m_x ),
                   g_target->Y() - ( m_parent->m_y + m_y ),
                   &output, &input );

        if( output < m_minOutput ) output = m_minOutput;
        if( output > m_maxOutput ) output = m_maxOutput;

        if( input < m_minInput ) input = m_minInput;
        if( input > m_maxInput ) input = m_maxInput;
        
        if( g_target->X() < m_parent->m_x + m_x + 50 )
        {
            SoundInstance *instance = g_app->m_soundSystem->GetSoundInstance( g_app->m_soundSystem->m_editorInstanceId );
            if( lmb && instance &&
                m_parameter->m_type == SoundParameter::TypeLinked )
            {
                instance->ForceParameter( *m_parameter, input );
            }
        }
        else
        {
            switch( m_parameter->m_type )
            {
                case SoundParameter::TypeFixedValue:
                    if( lmb )
                    {
                        m_parameter->m_outputLower = output;
                        m_parameter->Recalculate();
                    }
                    break;

                case SoundParameter::TypeRangedRandom:
                    if( lmb )
                    {
                        m_parameter->m_outputLower = output;
                        m_parameter->m_outputUpper = max( m_parameter->m_outputUpper, 
                                                          m_parameter->m_outputLower );                        
                        m_parameter->Recalculate();
                    }
                    if( rmb )
                    {
                        m_parameter->m_outputUpper = output;
                        m_parameter->m_outputLower = min( m_parameter->m_outputLower,
                                                          m_parameter->m_outputUpper );
                        m_parameter->Recalculate();
                    }
                    break;
                    
                case SoundParameter::TypeLinked:
                    if( lmb )
                    {
                        m_parameter->m_inputLower = input;
                        m_parameter->m_outputLower = output;
                        m_parameter->m_outputUpper = max( m_parameter->m_outputUpper, 
                                                          m_parameter->m_outputLower );
                    }
                    if( rmb )
                    {
                        m_parameter->m_inputUpper = input;
                        m_parameter->m_outputUpper = output;
                        m_parameter->m_outputLower = min( m_parameter->m_outputLower, 
                                                          m_parameter->m_outputUpper );
                    }
                    break;
            }
        }
    }
}
void SoundParameterGraph::RenderOutput( int realX, int realY )
{
    if( m_parameter->m_type == SoundParameter::TypeRangedRandom )
    {
        SoundEditorWindow *sew = (SoundEditorWindow *)EclGetWindow(SOUND_EDITOR_WINDOW_NAME);
        if( !sew ) return;

        SoundInstance *instance = g_app->m_soundSystem->GetSoundInstance( g_app->m_soundSystem->m_editorInstanceId );
        if( instance )
        {
            instance->UpdateParameter( *m_parameter );
        }
         
        float output = m_parameter->m_output;
        float x, minY, maxY;
        GetPosition( output, m_minInput, &x, &minY );
        GetPosition( output, m_maxInput, &x, &maxY );
        glColor4f( 0.5, 1.0, 0.5, 0.75 );
        glBegin( GL_LINES );
            glVertex2f( realX + x, realY + minY );
            glVertex2f( realX + x, realY + maxY);
        glEnd();

        float desiredOutput = m_parameter->m_desiredOutput;
        GetPosition( desiredOutput, m_minInput, &x, &minY );
        GetPosition( desiredOutput, m_maxInput, &x, &maxY );
        glColor4f( 0.5, 1.0, 0.5, 0.35 );
        glBegin( GL_LINES );
            glVertex2f( realX + x, realY + minY );
            glVertex2f( realX + x, realY + maxY);
        glEnd();
    }
    else if( m_parameter->m_type == SoundParameter::TypeLinked )
    {
        SoundEditorWindow *sew = (SoundEditorWindow *)EclGetWindow(SOUND_EDITOR_WINDOW_NAME);
        if( !sew ) return;

        SoundInstance *instance = g_app->m_soundSystem->GetSoundInstance( g_app->m_soundSystem->m_editorInstanceId );
        if( instance )
        {
            instance->UpdateParameter( *m_parameter );
        }
        float input = m_parameter->m_input;
        float output = m_parameter->m_output;

        float minX, minY, maxX, maxY;
        GetPosition( m_minOutput, input, &minX, &minY );
        GetPosition( output, m_minInput, &maxX, &maxY );

        glColor4f( 0.5, 1.0, 0.5, 0.75 );
        glBegin( GL_LINES );
            glVertex2f( realX + minX, realY + minY );
            glVertex2f( realX + maxX, realY + minY );

            glVertex2f( realX + maxX, realY + minY );
            glVertex2f( realX + maxX, realY + maxY );
        glEnd();

        glBegin( GL_LINE_LOOP );
            glVertex2f( realX + 2, realY + minY - 9 );
            glVertex2f( realX + 48, realY + minY - 9 );
            glVertex2f( realX + 48, realY + minY + 5 );
            glVertex2f( realX + 2, realY + minY + 5 );
        glEnd();

        g_editorFont.DrawText2DRight( realX + minX, realY + minY, 10, "%2.2", input );
        g_editorFont.DrawText2DCentre( realX + maxX, realY + maxY + 10, 10, "%2.2", output );

        float desiredOutput = m_parameter->m_desiredOutput;

        GetPosition( m_minOutput, input, &minX, &minY );
        GetPosition( desiredOutput, m_minInput, &maxX, &maxY );
        
        glColor4f( 0.5, 1.0, 0.5, 0.35 );
        glBegin( GL_LINES );
            glVertex2f( realX + minX, realY + minY );
            glVertex2f( realX + maxX, realY + minY );

            glVertex2f( realX + maxX, realY + minY );
            glVertex2f( realX + maxX, realY + maxY );
        glEnd();
    }
}