Example #1
0
bool
ProcessNode::setInput(const std::string& name, boost::shared_ptr<Data> data) {

	return getInput(name).accept(data);
}
bool CHistogram2D::compute() throw()
{
	typedef boost::shared_ptr<ImageType> ImagePtr;
	typedef typename ImageType::TDataType ValueType;
  ImagePtr imagePtr = static_pointer_cast<ImageType>( getInput() );
  ImagePtr classPtr = static_pointer_cast<ImageType>( getInput(1) );
  ImagePtr gradientPtr = static_pointer_cast<ImageType>( getInput(2) );
  if ( !checkInput<ImageType>( imagePtr, 2, 3 )
  	|| !checkInput<ImageType>( classPtr, 2, 3 )
  	|| !checkInput<ImageType>( gradientPtr, 2, 3 ) )
  {
    return false;
  }
	bModuleReady = true;
  deleteOldOutput();

  double dClassOneMean = 0.0;
  double dClassOneVariance = 0.0;
  vector<ValueType> classOneValuesVec;
  double dClassTwoMean = 0.0;
  double dClassTwoVariance = 0.0;
  vector<ValueType> classTwoValuesVec;

  uint uiClassOne = parameters.getUnsignedLong( "Class1" );
  uint uiClassTwo = parameters.getUnsignedLong( "Class2" );
  cerr << uiClassOne << " " << uiClassTwo << endl;
	// Calculate intensity mean and variance of the selected classes
	typename ImageType::iterator classIt = classPtr->begin();
	typename ImageType::iterator imageIt = imagePtr->begin();
	while( classIt != classPtr->end() )
	{
		if ( *classIt == static_cast<ValueType>( uiClassOne ) )
			classOneValuesVec.push_back( *imageIt );
		else if ( *classIt == static_cast<ValueType>( uiClassTwo ) )
			classTwoValuesVec.push_back( *imageIt );
		++classIt;
		++imageIt;
	}

  for_each( classOneValuesVec.begin(), classOneValuesVec.end(), dClassOneMean += _1 );
  dClassOneMean /= static_cast<double>( classOneValuesVec.size() );
  for_each( classOneValuesVec.begin(), classOneValuesVec.end(),
  	dClassOneVariance += ( _1 - dClassOneMean ) * ( _1 - dClassOneMean ) );
  dClassOneVariance /= static_cast<double>( classOneValuesVec.size() );
  dClassOneVariance = sqrt( dClassOneVariance );

	for_each( classTwoValuesVec.begin(), classTwoValuesVec.end(), dClassTwoMean += _1 );
  dClassTwoMean /= static_cast<double>( classTwoValuesVec.size() );
  for_each( classTwoValuesVec.begin(), classTwoValuesVec.end(),
  	dClassTwoVariance += ( _1 - dClassTwoMean ) * ( _1 - dClassTwoMean ) );
  dClassTwoVariance /= static_cast<double>( classTwoValuesVec.size() );
  dClassTwoVariance = sqrt( dClassTwoVariance );

cerr << " C1 (" << uiClassOne << ") : Mean " << dClassOneMean << " SD " << dClassOneVariance << endl
<< " C2 (" << uiClassTwo << ") : Mean " << dClassTwoMean << " SD " << dClassTwoVariance << endl;

	int rangeMin, rangeMax;
	rangeMin = static_cast<int>(
		std::min( dClassOneMean - dClassOneVariance, dClassTwoMean - dClassTwoVariance ) );
	rangeMax = static_cast<int>(
		std::max( dClassOneMean - dClassOneVariance, dClassTwoMean - dClassTwoVariance ) );

	ImagePtr tmp( new ImageType( *gradientPtr ) );
	classIt = imagePtr->begin();
	imageIt = tmp->begin();
	while( classIt != imagePtr->end() )
	{
		if ( *classIt < rangeMin || *classIt > rangeMax )
			*imageIt = 0;
		++classIt;
		++imageIt;
	}
	calculateHistogram( tmp );
	// Do a gaussian smoothing on the histogram
	// Compute gaussian mask
	double dSigma = parameters.getDouble( "HistoSmooth" );
cerr << "HistoSmooth " << dSigma << endl;
	int iMaskSize = static_cast<uint>( floor( 6.0 * dSigma + 0.5 ) );
	vector<double> dGaussMask;
	for( int i = -( iMaskSize / 2 ); i <= ( iMaskSize / 2 ); ++i )
	{
		double dExponential = ( 1.0 / sqrt( dSigma * dSigma * 2.0 * M_PI ) )
			* exp( static_cast<double>( -i * i ) / ( 2.0 * ( dSigma * dSigma ) ) );
		dGaussMask.push_back( dExponential );
	}

cerr << "Mask size " << iMaskSize << endl;

	// Shift histogram to attend smoothing
	vector<double> shiftedHisto;
	for( int i = 0; i < iMaskSize/2; ++i )
		shiftedHisto.push_back(0.0);
	for( uint i = 0; i < theHistogramVec[0].size(); ++i )
	{
		shiftedHisto.push_back( theHistogramVec[0][i] );
	}
	for( int i = 0; i <= iMaskSize/2; ++i )
		shiftedHisto.push_back(0.0);
   const uint uiShift = iMaskSize/2;
	vector<double> smoothedHisto( shiftedHisto.size() + uiShift);

	for( uint i = uiShift+1; i < shiftedHisto.size() - uiShift; ++i )
	{
		double smoothed = 0.0;
		for( int j = -(uiShift+1); j <= uiShift; ++j )
		{
			smoothed += shiftedHisto[i+j]*dGaussMask[j+uiShift+1];
		}
		smoothedHisto[i] = smoothed;
	}
   smoothedHisto = shiftedHisto;
	// Smooth
	// Reshift histogram
	// Determine the global maximum g1
	uint g1 = 0;
	double gv1 = 0.0;
	for( uint i = uiShift+1; i < smoothedHisto.size(); ++i )
	{
		if ( smoothedHisto[i] >= smoothedHisto[i-1] && smoothedHisto[i] >= gv1 )
		{
			gv1 = smoothedHisto[i]; g1 = i;
		}
		else if ( smoothedHisto[i] < smoothedHisto[i-1] )
			break;
	}
	// Determine next global maximum g2
/*	if ( g1 == 0 ) g1 = parameters.getUnsignedLong("Shift");*/
	uint t = g1 + parameters.getUnsignedLong("Shift");
	while( smoothedHisto[t] <= smoothedHisto[t-1] )
		++t;
	uint g2 = t+1;
	double gv2 = 0;
	for( uint i = t+1; i < smoothedHisto.size(); ++i )
	{
		if ( smoothedHisto[i] > smoothedHisto[i-1] && smoothedHisto[i] > gv2 )
		{
			gv2 = smoothedHisto[i]; g2 = i;
		}
		else if ( smoothedHisto[i] < smoothedHisto[i-1] )
			break;
	}
	if ( g1 == 0 )
	{
		g1 = g2;
		t = g1+parameters.getUnsignedLong("Shift");
		while( smoothedHisto[t] <= smoothedHisto[t-1] )
			++t;
		g2 = t+1;
		gv2 = 0;
		for( uint i = t+1; i < smoothedHisto.size(); ++i )
		{
			if ( smoothedHisto[i] > smoothedHisto[i-1] && smoothedHisto[i] > gv2 )
			{
				gv2 = smoothedHisto[i]; g2 = i;
			}
			else if ( smoothedHisto[i] < smoothedHisto[i-1] )
				break;
		}
	}
	if ( g2-g1 > (2 * parameters.getUnsignedLong("Shift")) )
		g2 = g1 + 2 * parameters.getUnsignedLong("Shift");
   g1--;
   g2--;
 	cerr << "Threshold values are " << g1 << " and " << g2;
	parameters.setUnsignedLong("T1", static_cast<ulong>( g1 * 0.33)-1 );
	parameters.setUnsignedLong("T2",
		static_cast<ulong>( std::max( g1 * 0.66, g1 + parameters.getDouble("Shift") + 1) ) - 1 );
ofstream file( "/home/hendrik/orig_histogram.data" );
	for( uint i = 0; i <= theHistogramVec[0].size(); ++i )
	{
		file << i << " " << theHistogramVec[0][i] << endl;
	}
	file.close();
ofstream file2( "/home/hendrik/shifted_histogram.data" );
	for( uint i = 0; i <= shiftedHisto.size(); ++i )
	{
		file2 << i << " " << shiftedHisto[i] << endl;
	}
	file2.close();
ofstream file3( "/home/hendrik/smoothed_histogram.data" );
	for( uint i = 0; i <= smoothedHisto.size(); ++i )
	{
		file3 << i << " " << smoothedHisto[i] << endl;
	}
	file3.close();
	return true;
}
Example #3
0
BOOL BuildGUI(char *screenname)
{
  Object *MUISave, *MUIUse, *MUICancel;
  Object *page1,*page2;
  Object *MUITFreq,*MUITChannels,*MUITOutvol,*MUITMonvol,*MUITGain,*MUITInput,*MUITOutput,*MUITDebug,*MUITEcho,*MUITSurround,*MUITClipvol,*MUITCpu,*MUITACTime,*MUITScalemode;

  UpdateStrings();

  MUIMasterBase = (void *)OpenLibrary("muimaster.library", MUIMASTER_VLATEST);
  if(MUIMasterBase == NULL)
  {
    Printf((char *) msgTextNoOpen, (ULONG) "muimaster.library", MUIMASTER_VLATEST);
    Printf("\n");
    return FALSE;
  }

  page1 = HGroup,
    Child, VGroup,
      Child, MUIUnit = CycleObject,
        MUIA_CycleChain, 1,
        MUIA_Cycle_Entries, Units,
        MUIA_Cycle_Active, state.UnitSelected,
      End,
      Child, ListviewObject,
        MUIA_CycleChain, 1,
        MUIA_Listview_List, MUIList = ListObject,
          InputListFrame,
          MUIA_List_AutoVisible, TRUE,
        End,
      End,
      Child, HGroup,
        ReadListFrame,
        MUIA_Background, MUII_TextBack,
        Child, TextObject,
          MUIA_Text_Contents, msgProperties,
          MUIA_Text_SetMax, TRUE,
        End,
        Child, MUIInfos = TextObject,
          MUIA_Text_Contents, "\n\n\n\n\n\n",
          MUIA_Text_SetMin, FALSE,
        End,
      End,
    End,
    Child, BalanceObject,
    End,
    Child, VGroup,
      Child, HVSpace,
      Child, ColGroup(3),
        GroupFrameT(msgOptions),
        Child, MUITFreq = SpecialButton((STRPTR)msgOptFrequency),
        Child, MUIFreq = SpecialSlider(0,max(state.Frequencies-1,0),state.FreqSelected),
        Child, MUILFreq = SpecialLabel(getFreq()),
        Child, MUITChannels = SpecialButton((STRPTR)msgOptChannels),
        Child, MUIChannels = SpecialSlider(1,state.Channels,state.ChannelsSelected),
        Child, MUILChannels = SpecialLabel(getChannels()),
        Child, MUITOutvol = SpecialButton((STRPTR)msgOptVolume),
        Child, MUIOutvol = SpecialSlider(0,max(state.OutVols-1,0),state.OutVolSelected),
        Child, MUILOutvol = SpecialLabel(getOutVol()),
        Child, MUITMonvol = SpecialButton((STRPTR)msgOptMonitor),
        Child, MUIMonvol = SpecialSlider(0,max(state.MonVols-1,1),state.MonVolSelected),
        Child, MUILMonvol = SpecialLabel(getMonVol()),
        Child, MUITGain = SpecialButton((STRPTR)msgOptGain),
        Child, MUIGain = SpecialSlider(0,max(state.Gains-1,0),state.GainSelected),
        Child, MUILGain = SpecialLabel(getGain()),
        Child, MUITInput = SpecialButton((STRPTR)msgOptInput),
        Child, MUIInput = SpecialSlider(0,max(state.Inputs-1,0),state.InputSelected),
        Child, MUILInput = SpecialLabel(getInput()),
        Child, MUITOutput = SpecialButton((STRPTR)msgOptOutput),
        Child, MUIOutput = SpecialSlider(0,max(state.Outputs-1,0),state.OutputSelected),
        Child, MUILOutput = SpecialLabel(getOutput()),
      End,
      Child, MUIPlay = SimpleButton(msgButtonPlay),
      Child, HVSpace,
    End,
  End;

  page2 = VGroup,
    Child, HVSpace,
    Child, HGroup,
      Child, HVSpace,
      Child, ColGroup(2),
        GroupFrameT(msgGlobalOptions),
        Child, MUITDebug = SpecialButton((STRPTR)msgGlobOptDebugLevel),
        Child, MUIDebug = CycleObject,
          MUIA_CycleChain, 1,
          MUIA_Cycle_Entries, DebugLabels,
          MUIA_Cycle_Active, globalprefs.ahigp_DebugLevel,
        End,
        Child, MUITEcho = SpecialButton((STRPTR)msgGlobOptEcho),
        Child, MUIEcho  = CycleObject,
          MUIA_CycleChain, 1,
          MUIA_Cycle_Entries, EchoLabels,
          MUIA_Cycle_Active, (globalprefs.ahigp_DisableEcho ? 2 : 0) | (globalprefs.ahigp_FastEcho ? 1 : 0),
          MUIA_Disabled, AHIBase->lib_Version >= 5,
        End,
        Child, MUITSurround = SpecialButton((STRPTR)msgGlobOptSurround),
        Child, MUISurround = CycleObject,
          MUIA_CycleChain, 1,
          MUIA_Cycle_Entries, SurroundLabels,
          MUIA_Cycle_Active, globalprefs.ahigp_DisableSurround,
          MUIA_Disabled, AHIBase->lib_Version >= 5,
        End,
        Child, MUITClipvol = SpecialButton((STRPTR)msgGlobOptMasterVol),
        Child, MUIClipvol = CycleObject,
          MUIA_CycleChain, 1,
          MUIA_Cycle_Entries, ClipMVLabels,
          MUIA_Cycle_Active, globalprefs.ahigp_ClipMasterVolume,
          MUIA_Disabled, AHIBase->lib_Version >= 5,
        End,
        Child, MUITCpu = SpecialButton((STRPTR)msgGlobOptCPULimit),
        Child, MUICpu = SliderObject,
          MUIA_CycleChain, 1,
          MUIA_Slider_Horiz, TRUE,
          MUIA_Numeric_Min, 0,
          MUIA_Numeric_Max, 100,
          MUIA_Numeric_Value,(globalprefs.ahigp_MaxCPU * 100 + 32768) / 65536,
          MUIA_Numeric_Format,"%ld%%",
        End,
        Child, MUITACTime = SpecialButton((STRPTR)msgGlobOptACTime),
        Child, MUIACTime = SliderObject,
          MUIA_CycleChain, 1,
          MUIA_Slider_Horiz, TRUE,
          MUIA_Numeric_Min, 0,
          MUIA_Numeric_Max, 100,
          MUIA_Numeric_Value,(globalprefs.ahigp_AntiClickTime * 1000 + 32768) >> 16,
          MUIA_Numeric_Format,"%ld ms",
          MUIA_Disabled, AHIBase->lib_Version <= 4,
        End,
        Child, MUITScalemode = SpecialButton((STRPTR)msgOptScalemode),
        Child, MUIScalemode = CycleObject,
          MUIA_CycleChain, 1,
          MUIA_Cycle_Entries, ScaleLabels,
          MUIA_Cycle_Active, globalprefs.ahigp_ScaleMode,
          MUIA_Disabled, AHIBase->lib_Version <= 4,
        End,
      End,
      Child, HVSpace,
    End,
    Child, HVSpace,
  End;

  MUIApp = ApplicationObject,
    MUIA_Application_Title, (char *) msgTextProgramName,
    MUIA_Application_Version, Version,
    MUIA_Application_Copyright, "©1996-2004 Martin Blom",
    MUIA_Application_Author, "Stéphane Barbaray/Martin Blom",
    MUIA_Application_Base, "AHI",
    MUIA_Application_HelpFile, HELPFILE,
    MUIA_Application_Menustrip, MUIMenu = MUI_MakeObject(MUIO_MenustripNM,Menus,0),
    MUIA_Application_SingleTask, TRUE,
    SubWindow, MUIWindow = WindowObject,
      MUIA_Window_Title, (char *) msgTextProgramName,
      MUIA_Window_ID   , MAKE_ID('M','A','I','N'),
      MUIA_HelpNode, "AHI",
      WindowContents, VGroup,
       Child, RegisterGroup(PageNames),
         MUIA_CycleChain, 1,
         Child, page1,
         Child, page2,
       End,
       Child, HGroup,
          Child, MUISave = SimpleButton(msgButtonSave),
          Child, MUIUse = SimpleButton(msgButtonUse),
          Child, MUICancel = SimpleButton(msgButtonCancel),
        End,
      End,
    End,
  End;
  
  if( MUIApp != NULL )
  {
    APTR item = (APTR)DoMethod(MUIMenu,MUIM_FindUData,ACTID_ICONS);
    if(item)
    {
      set(item, MUIA_Menuitem_Checked, SaveIcons);
    }
    DoMethod(MUIWindow, MUIM_MultiSet, MUIA_Text_PreParse,"\033l",MUILFreq,MUILChannels,MUILOutvol,MUILMonvol,MUILGain,MUILInput,MUILOutput,NULL);
    DoMethod(MUIWindow, MUIM_MultiSet, MUIA_CycleChain, 1, MUISave,MUIUse,MUICancel,NULL);

    DoMethod(MUITFreq, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIFreq);
    DoMethod(MUITChannels, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIChannels);
    DoMethod(MUITOutvol, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIOutvol);
    DoMethod(MUITMonvol, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIMonvol);
    DoMethod(MUITGain, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIGain);
    DoMethod(MUITInput, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIInput);
    DoMethod(MUITOutput, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIOutput);
    DoMethod(MUIPlay, MUIM_Notify, MUIA_Pressed, FALSE, MUIApp, 2, MUIM_Application_ReturnID, ACTID_PLAY);
    DoMethod(MUITDebug, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIDebug);
    DoMethod(MUITEcho, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIEcho);
    DoMethod(MUITSurround, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUISurround);
    DoMethod(MUITClipvol, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIClipvol);
    DoMethod(MUITCpu, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUICpu);
    DoMethod(MUITACTime, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIACTime);
    DoMethod(MUITScalemode, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIScalemode);

    DoMethod(MUIWindow, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, MUIApp, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
    DoMethod(MUISave, MUIM_Notify, MUIA_Pressed, FALSE, MUIApp, 2, MUIM_Application_ReturnID, ACTID_SAVE);
    DoMethod(MUIUse, MUIM_Notify, MUIA_Pressed, FALSE, MUIApp, 2, MUIM_Application_ReturnID, ACTID_USE);
    DoMethod(MUICancel, MUIM_Notify, MUIA_Pressed, FALSE, MUIApp, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
    DoMethod(MUIUnit, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID, ACTID_UNIT);
    DoMethod(MUIList, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID, ACTID_MODE);
    DoMethod(MUIDebug, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID,  ACTID_DEBUG);
    DoMethod(MUISurround, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID,  ACTID_SURROUND);
    DoMethod(MUIEcho, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID,  ACTID_ECHO);
    DoMethod(MUICpu, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID,  ACTID_CPULIMIT);
    DoMethod(MUIClipvol, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID,  ACTID_CLIPMV);
    DoMethod(MUIACTime, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID,  ACTID_ACTIME);
    DoMethod(MUIScalemode, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID,  ACTID_SCALEMODE);
    DoMethod(MUIFreq, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIV_Notify_Self, 3, MUIM_CallHook, &hookSlider, MUIV_TriggerValue);
    DoMethod(MUIChannels, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIV_Notify_Self, 3, MUIM_CallHook, &hookSlider, MUIV_TriggerValue);
    DoMethod(MUIOutvol, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIV_Notify_Self, 3, MUIM_CallHook, &hookSlider, MUIV_TriggerValue);
    DoMethod(MUIMonvol, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIV_Notify_Self, 3, MUIM_CallHook, &hookSlider, MUIV_TriggerValue);
    DoMethod(MUIGain, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIV_Notify_Self, 3, MUIM_CallHook, &hookSlider, MUIV_TriggerValue);
    DoMethod(MUIInput, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIV_Notify_Self, 3, MUIM_CallHook, &hookSlider, MUIV_TriggerValue);
    DoMethod(MUIOutput, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIV_Notify_Self, 3, MUIM_CallHook, &hookSlider, MUIV_TriggerValue);
    set(MUIWindow, MUIA_Window_Open, TRUE);
    GUINewUnit();
    return TRUE;
  }
  return FALSE;
}
Example #4
0
ErrorCode updateAsserv(Module* parent, OriginWord port)
{
  ModuleValue kp, ki, kd;
  ModuleValue command, output, derivThreshold, measure;
  ModuleValue newError, derivError;
  //OpFunc h = ((Asserv*)parent->fun)->h;
  OriginWord i;
  ErrorCode error;
  Asserv *asserv = (Asserv*)parent->fun;

   // debug("A");

  /* Si la sortie est à jour, pas besoin de refaire le calcul */
  if( outputIsUpToDate(parent, port) )
  {
    return NO_ERR;
  }

  /* MAJ des entrées */
  for(i=0; i < parent->nbInputs; i++)
  {
    error = updateInput(parent, i);
    if(error != NO_ERR)
    {
      return error;
    }
  }

  /* On récupère les entrées */

  /* Les coefficients du PID */
  kp = getInput(parent, AsservKp);
  ki = getInput(parent, AsservKi);
  kd = getInput(parent, AsservKd);

  /* L'entrée de commande auquelle on applique la boite H1*/
  command = getInput(parent, AsservCommand);
  /* La dérivée maximale */
  derivThreshold = getInput(parent, AsservDeriv);
  /* La mesure du moteur auquel on applique la boite H2 */
  measure = getInput(parent, AsservMeasure);

  /* Calcul de l'erreur (sortie - entrée)*/
  newError = command - measure;

  /* Mise à jour de la dérivée de l'erreur, de l'intégrale de l'erreur, et de l'erreur elle meme */
  derivError = newError - asserv->oldError;
  asserv->integral += newError;
  asserv->oldError = newError;

  /* On passe aux choses serieuses : calcul de la commande à envoyer au moteur */
  output = (ModuleValue)((
            (int32_t)kp * (int32_t)newError // terme proportionnel
          + (int32_t)ki * (int32_t)asserv->integral // terme intégral
          + (int32_t)kd * (int32_t)derivError
	   ) / 1000); // terme dérivé

  
  
  /* On ecrete si trop grand avec la derivée maximale */
  if(output > derivThreshold)
  {
    output = derivThreshold;
  }
  else if(output < -derivThreshold)
  {
    output = -derivThreshold;
  }
  
  // debug
    if (parent->isVerbose)
    {
      /*BACKUP
      debug("\tAsserv -> wanted   : 0x%l\n", (uint32_t)command);
      debug("\tAsserv -> measure  : 0x%l\n", (uint32_t)measure);
      debug("\t newError          : 0x%l\n", (uint32_t)newError);
      //debug("\t integrale         : 0x%l\n", (uint32_t)asserv->integral);
      //debug("\t derivee           : 0x%l\n", (uint32_t)derivError);
      debug("\tAsserv -> output   : 0x%l\n", (uint32_t)output);
      //debug("\tAsserv -> vi1      : 0x%l\n", (uint32_t)((kp * newError) / 1000 + (ki * asserv->integral) / 1000 + (kd * derivError) / 1000));
      //debug("\tAsserv -> vi2      : 0x%l\n", (uint32_t)((kp * newError + ki * asserv->integral + kd * derivError) / 1000));
      debug("\t ---- Autre asserv ---- \n");*/
      
      
      debug("m: 0x%l\r\nc: 0x%l\r\n", (uint32_t)measure, (uint32_t)command);
       // debug("\nW 0x%l\r\n M 0x%l\r\n NE 0x%l\r\n O 0x%l\r\n", (uint32_t)command, (uint32_t)measure, (uint32_t)newError, (uint32_t)output);
    }
  
  
  /* On envoie la commande sur la sortie port */
  setOutput(parent, port, output);
    // debug("a: 0x%l\r\n", (uint32_t)output);

  return NO_ERR;
}
Example #5
0
File: kerosin.c Project: C3MA/r0ket
void main_kerosin(void) {

	uint8_t enterCnt = 0;
	uint8_t buffer[64];
	
//	cpuInit();                                // Configure the CPU
	systickInit(CFG_SYSTICK_DELAY_IN_MS);     // Start systick timer
	gpioInit();                               // Enable GPIO
	pmuInit();                                // Configure power management
	adcInit();                                // Config adc pins to save power
	lcdInit();
		
    DoString(10,5,"USB plug");

	// Initialise USB CDC
#ifdef CFG_USBCDC
    DoString(10, 15, "USBCDC");
    lastTick = systickGetTicks();   // Used to control output/printf timing
    CDC_Init();                     // Initialise VCOM
    USB_Init();                     // USB Initialization
    USB_Connect(TRUE);              // USB Connect
    // Wait until USB is configured or timeout occurs
    uint32_t usbTimeout = 0; 
    while ( usbTimeout < CFG_USBCDC_INITTIMEOUT / 10 )
    {
		if (USB_Configuration) break;
		systickDelay(10);             // Wait 10ms
		usbTimeout++;
    }
#endif
	  // Printf can now be used with UART or USBCDC
	
	puts("Hello World");

	
	DoString(10, 25, "Enter:");
	lcdDisplay();

	
	int readData;
    while (1) {
				
		switch (getInput()) {
			case BTN_ENTER:
				enterCnt++;
				puts("ENTER\t");
				buffer[0] = '0' + enterCnt;
				buffer[1] = 0;
				puts(buffer);
				puts("\r\n");
				DoInt(50, 25, (int) (enterCnt));
				lcdDisplay();				
				break;
			case BTN_LEFT:
				readData = CDC_GetInputBuffer(buffer, sizeof(buffer));
				
				DoString(5, 40, buffer);
				DoString(1, 50, "Received: ");
				DoInt(57, 50, readData);
				lcdDisplay();
				break;
			default:
				break;
		}		
	}
}
Example #6
0
int main(void)
{
	cpu_clock_init_();
//	cpu_clock_pll1_max_speed();
	scu_pinmux(RF_EN_PIN,SCU_GPIO_NOPULL|RF_EN_FUNC);
	GPIO_DIR(RF_EN_GPORT) |= RF_EN_GPIN;
	gpio_clear(RF_EN_GPORT, RF_EN_GPIN); /* RF off */

    // Config LED as out
	scu_pinmux(LED1_PIN,SCU_GPIO_NOPULL|LED1_FUNC);
	GPIO_DIR(LED1_GPORT) |= LED1_GPIN;

	inputInit();

    lcdInit();
    lcdFill(0xff);
	setSystemFont();
	char tu=0,td=0,tl=0,tr=0,tm=0;
	char led=0;
	lcdPrintln("Sec-Test v2");
	lcdPrintln("");

	int ctr=0;
	int k=0;
	/* Blink LED1 on the board. */
	while (1) 
	{
		lcdSetCrsr(0,16);
		lcdPrint(IntToStr(tu,2,F_HEX)); lcdPrintln(" Up");
		lcdPrint(IntToStr(td,2,F_HEX)); lcdPrintln(" Down");
		lcdPrint(IntToStr(tl,2,F_HEX)); lcdPrintln(" Left");
		lcdPrint(IntToStr(tr,2,F_HEX)); lcdPrintln(" Right");
		lcdPrint(IntToStr(tm,2,F_HEX)); lcdPrintln(" Enter");
		lcdDisplay(); 
		switch(getInput()){
			case BTN_UP:
				tu=1-tu;
				if (tu){
				}else{
				};
				break;
			case BTN_DOWN:
				td=1-td;
				if (td){
				}else{
				};
				break;
			case BTN_LEFT:
				tl=1-tl;
				if (tl){
				}else{
				};
				break;
			case BTN_RIGHT:
				tr=1-tr;
				if (tr){
				}else{
				};
				break;
			case BTN_ENTER:
				tm=1-tm;
				if (tm){
				}else{
				};
				break;
		};

		led=1-led;
		if (led){
			gpio_set(LED1_GPORT, LED1_GPIN); /* LED on */
		}else{
			gpio_clear(LED1_GPORT, LED1_GPIN); /* LED off */
//			delayNop(200000);
		};

		ctr++;
		lcdNl();
		lcdPrint(IntToStrX(ctr,4));
	}

	return 0;
}
Example #7
0
int main(int argc, char** argv) {
	double begin, end;
	MPI_Init(&argc, &argv);
	MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
	MPI_Comm_rank(MPI_COMM_WORLD, &myid);
	//init
	if (myid == 0) {
		// Get input.
		getInput();
		begin = MPI_Wtime();
	}

	//brodcast n
	MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
	//brodcast dist
	MPI_Bcast(dist, MAXN * MAXN, MPI_DOUBLE, 0, MPI_COMM_WORLD);
	//brodcast nearest
	MPI_Bcast(nearest, MAXN * MAXN, MPI_INT, 0, MPI_COMM_WORLD);

	Tour gBestTour;

	int i, j, k;
	for (loopRound = 0; loopRound < LOOPTIME; loopRound ++) {
		Tour localBestTour;
		for (i = 1; i <= 1; i ++) {
			init();
			if (myid == 0 && loopRound == 0 && i == 1) gBestTour = bestTour;
			if (i == 1) localBestTour = bestTour;
			while (1) {
				int update = search(1);
				if (!update) break;
			}
			if (bestTour.length < localBestTour.length) {
				localBestTour = bestTour;
			}
		}
		// Reduce
		int changed = 0;
		if (myid != 0) {
			MPI_Send(localBestTour.p, MAXN, MPI_INT, 0, 0, MPI_COMM_WORLD);
			MPI_Send(&localBestTour.length, 1, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD);
			MPI_Recv(&changed, 1, MPI_INT, 0, 2, MPI_COMM_WORLD, &status);
		} else {
			if (localBestTour.length < gBestTour.length)
				gBestTour = localBestTour;
			for (i = 1; i <= n; i ++)
				for (j = i + 1; j <= n; j ++)
					if (inTour(localBestTour.p, i, j)) {
						fixed[i][j] ++;
						fixed[j][i] ++;
					}
			for (k = 0; k < numprocs - 1; k++) {
				MPI_Recv(recvTour.p, MAXN, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
				MPI_Recv(&recvTour.length, 1, MPI_DOUBLE, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD, &status);
				if (recvTour.length < gBestTour.length)	gBestTour = recvTour;
				if (recvTour.length < localBestTour.length) localBestTour = recvTour;
				for (i = 1; i <= n; i ++)
					for (j = i + 1; j <= n; j ++)
						if (inTour(recvTour.p, i, j)) {
							fixed[i][j] ++;
							fixed[j][i] ++;
						}
			}
			printf("loopRound %d, gBestTour.length = %lf\n", loopRound, gBestTour.length);
			bestTours[loopRound] = gBestTour;
			if (loopRound > 0 && fabs(bestTours[loopRound].length - bestTours[loopRound-1].length) > 1e-3) changed = 1;
			for (j = 1; j < numprocs; j++)
				MPI_Send(&changed, 1, MPI_INT, j, 2, MPI_COMM_WORLD);
			k = 0;
			memset(fixedEdges, 0, sizeof(fixedEdges));
			for (i = 1; i <= n; i ++)
				for (j = i + 1; j <= n; j ++) {
					if (fixed[i][j] == (loopRound + 1) * numprocs) {
						fixedEdges[k][0] = i;
						fixedEdges[k][1] = j;
						k ++;
					}
				}
		}
		MPI_Bcast(fixedEdges, MAXN * 2, MPI_INT, 0, MPI_COMM_WORLD);
	}

	MPI_Barrier(MPI_COMM_WORLD);

	if (myid == 0) {
		end = MPI_Wtime();
		printf("\nresult:\n");
		printf("time = %lf\n", end - begin);
		printf("len = %lf\n", gBestTour.length);
		for (i = 1; i <= n; i ++) {
			printf("%d ", gBestTour.p[i]);
		}
		printf("\n");
	}

	MPI_Finalize();
	return 0;
}
Example #8
0
    void BfVM::runInstruction(const BfOpcode &op) {
        qDebug("BfVM::runInstruction()");
        qDebug("IP=%d\t%s\tDP=%d (%d)",m_IP,OPCODENAMES[op],m_DP,m_memory[m_DP]);
        switch(op) {
        case(BRK): // breakpoint, yay
            emit breakpoint(m_IP, m_DP);
            m_stateMachine->postEvent(new BreakpointEvent);
            ++m_IP;
            break;
        case(DPINC):  // ++DP
            /* there's no need to check for overflows here or in SUBDP since it's desireable
               that the DP roll over when reaching either end */
            emit DPChanged(++m_DP);
            ++m_IP;
            break;

        case(DPDEC): // --DP
            emit DPChanged(--m_DP);
            ++m_IP;
            break;

        case(ADD): // ++*DP
            // Again no overflow checking since it's OK to overflow
            emit memChanged(m_DP, ++m_memory[m_DP]);
            ++m_IP;
            break;

        case(SUB): // --*DP
            emit memChanged(m_DP, --m_memory[m_DP]);
            ++m_IP;
            break;

        case(JZ): // Jump to command AFTER matching JNZ if DP points to 0. NOP if *DP!=0
            if(m_memory[m_DP] == 0) {
                qDebug() << "JZ: *DP==0, set IP to"<<m_jmps->value(m_IP)+1;
                m_IP = m_jmps->value(m_IP)+1; // AFTER the matching JNZ!
                break;
            }
            ++m_IP;
            break;

        case(JNZ): // Jump to command AFTER matching JZ if DP points to 0. NOP if *DP==0
            if(m_memory[m_DP] != 0) {
                qDebug() << "JNZ: *DP!=0, set IP to"<<m_jmps->key(m_IP)+1;
                m_IP = m_jmps->key(m_IP)+1; // AFTER the matching JZ!
                break;
            }
            ++m_IP;
            break;
        case(OUT):
            emit output(m_memory[m_DP]);
            qDebug() << "BfVM::runInstruction() output:"<<m_memory[m_DP];
            ++m_IP;
            break;

        case(INP):
            /* this is a tad complicated: if there is no data in the input buffer, the
               function checkInputBuffer() will post an event to the state machine. In this
               case, the IP should NOT be advanced since we want the VM to continue from
               this exact same point after the input buffer has been filled and we can
               *actually* do the INP command.

               In others words, if there's nothing in the input buffer we just leave
               the handling of the situation to the state machine.*/

            if(checkInputBuffer()) {
                m_memory[m_DP] = getInput();
                qDebug("INP read %d",m_memory[m_DP]);
                ++m_IP;
#ifndef QT_NO_DEBUG
        listStates();
#endif
            } else {
                qDebug("INP input buffer empty");
#ifndef QT_NO_DEBUG
        listStates();
#endif
            }
            break;
        default:
            qDebug() << "WEIRD INSTRUCTION FOUND:"<<QString::number(op);
            throw std::runtime_error("VM got a bad instruction");
        }
        qDebug("New IP=%d DP=%d (%d)",m_IP,m_DP,m_memory[m_DP]);
    }
Example #9
0
main()
{
	int winning[SIZE] = { 1, 3, 5, 7, 9, 11 }; // winning numbers + bonus

    register int i;
	char option;
	int pickedNumbers[SIZE];
    int freq[MAX+1] = {0}; // max is the highest number user can enter, so only MAX elements are needed in this array - MAX+1 so number is same as position - initially set to 0
    int num_match;
    int numbersEntered = 0; // false
    int b_match = 0; // bonus does not match

	//main program loop
	//
	do
    {
        system("cls");//clears the screen
        printf("Enter 1 - 5, or 0 to select an option from below:\n\n");

        printf("________________________________________________________________________________\n");
        printf("(1) Enter the 6 Numbers ( range: 1 - 42 )\n\n");
        printf("(2) Display the Entered Numbers\n\n");
        printf("(3) Display Numbers in Increasing Order\n\n");
        printf("(4) Did I Win?\n\n");
        printf("(5) Display Frequency of Numbers Entered\n\n");
        printf("(0) Exit Program\n");
        printf("________________________________________________________________________________\n\n");
        
        printf("Enter option:  ");
        scanf("%1s", &option);
        flushall();  // clear buffer
        
        system("cls");//clears the screen

        switch (option)
        {
        	case '1':
        	{
        		//get input
        		getInput(pickedNumbers, freq);
                numbersEntered++;
        		break;
        	}//end case 1
        	case '2':
        	{
                if ( numbersEntered == 0 )
                {
                    printf("**You did not Enter Your Numbers\n\n");
                }//end if

        		else // display numbers
        		{
                    displayInput(pickedNumbers);
        		}//end else
                break;
        	}//end case 2
        	case '3':
        	{
                if ( numbersEntered == 0 )
                {
                    printf("**You did not Enter Your Numbers\n\n");
                }
        		else // sort the numbers
        		{
                    sort(pickedNumbers);
        		}
                break;
        	}//end case 3
        	case '4':
        	{
                if ( numbersEntered == 0 )
                {
                    printf("**You did not Enter Your Numbers\n\n");
                }
        		else // see match
        		{
                    num_match = compare(pickedNumbers, winning);
                    
                    // check bonus
                    //
                    for ( i = 0; i < SIZE; i++ )
                    {
                        if ( *(pickedNumbers + i) == BONUS )
                        {
                            b_match++;
                            break; // dont check rest of numbers 
                        }//end if
                    }//end for

                    switch ( num_match )
                    {
                        case 3:
                        {
                            if ( b_match > 0 )
                                printf("You Won a Cinema Ticket\n");
                            else
                                printf("You Lost :(\n");
                            break;
                        }
                        case 4:
                        {
                            if ( b_match > 0 )
                                printf("You Won a Weekend Away\n");
                            else
                                printf("You Won a Night Out\n");
                            break;
                        }
                        case 5:
                        {
                            if ( b_match > 0 )
                                printf("You Won a New Car\n");
                            else
                                printf("You Won a Holiday\n");
                            break;
                        }
                        case 6:
                        {
                            printf("You Won the JACKPOT!!!\n");
                            break;
                        }
                        default:
                        {
                            printf("You Lost :(\n");
                        }
                    }//end switch
                    
        		}//end else
                break;
        	}//end case 4
        	case '5':
        	{
                if ( numbersEntered == 0 )
                {
                    printf("**You did not Enter Your Numbers\n");
                }//end if
        		else //get frequency
        		{
                    frequency( freq );
                }//end else
                break;
        	}//end case 5
        	case '0':
        	{
        		exitp();
        		break;
        	}//end case 0
        	default:
        	{
                system("cls");//clears the screen
                printf("**Error: Input value not valid\n\n");
            }
        }//end switch

        printf("\n\n**Press Enter to Continue");
        getchar();
    }//end do
    while ( option != '0' );
} //end main
Example #10
0
void
ProcessNode::unsetInput(const std::string& name) {

	return getInput(name).unset();
}
Example #11
0
int GUI_HoF::optionsButton(Button *button) {
	PauseTimer pause(*_vm->_timer);

	_restartGame = false;
	_reloadTemporarySave = false;

	updateButton(&_vm->_inventoryButtons[0]);

	if (!_screen->isMouseVisible() && button)
		return 0;

	_vm->showMessage(0, 0xCF);

	if (_vm->_mouseState < -1) {
		_vm->_mouseState = -1;
		_screen->setMouseCursor(1, 1, _vm->getShapePtr(0));
		return 0;
	}

	int oldHandItem = _vm->_itemInHand;
	_screen->setMouseCursor(0, 0, _vm->getShapePtr(0));
	_vm->displayInvWsaLastFrame();
	_displayMenu = true;

	for (uint i = 0; i < ARRAYSIZE(_menuButtons); ++i) {
		_menuButtons[i].data0Val1 = _menuButtons[i].data1Val1 = _menuButtons[i].data2Val1 = 4;
		_menuButtons[i].data0Callback = _redrawShadedButtonFunctor;
		_menuButtons[i].data1Callback = _menuButtons[i].data2Callback = _redrawButtonFunctor;
	}

	initMenuLayout(_mainMenu);
	initMenuLayout(_gameOptions);
	initMenuLayout(_audioOptions);
	initMenuLayout(_choiceMenu);
	_loadMenu.numberOfItems = 6;
	initMenuLayout(_loadMenu);
	initMenuLayout(_saveMenu);
	initMenuLayout(_savenameMenu);
	initMenuLayout(_deathMenu);

	_currentMenu = &_mainMenu;

	if (_vm->_menuDirectlyToLoad) {
		backUpPage1(_vm->_screenBuffer);
		setupPalette();

		_loadedSave = false;

		loadMenu(0);

		if (_loadedSave) {
			if (_restartGame)
				_vm->_itemInHand = kItemNone;
		} else {
			restorePage1(_vm->_screenBuffer);
			restorePalette();
		}

		resetState(-1);
		_vm->_menuDirectlyToLoad = false;
		return 0;
	}

	if (!button) {
		_currentMenu = &_deathMenu;
		_isDeathMenu = true;
	} else {
		_isDeathMenu = false;
	}

	backUpPage1(_vm->_screenBuffer);
	setupPalette();
	initMenu(*_currentMenu);
	_madeSave = false;
	_loadedSave = false;
	updateAllMenuButtons();

	if (_isDeathMenu) {
		while (!_screen->isMouseVisible())
			_screen->showMouse();
	}

	while (_displayMenu) {
		processHighlights(*_currentMenu);
		getInput();
	}

	if (_vm->_runFlag && !_loadedSave && !_madeSave) {
		restorePalette();
		restorePage1(_vm->_screenBuffer);
	}

	if (_vm->_runFlag)
		updateMenuButton(&_vm->_inventoryButtons[0]);

	resetState(oldHandItem);

	if (!_loadedSave && _reloadTemporarySave) {
		_vm->_unkSceneScreenFlag1 = true;
		_vm->loadGameStateCheck(999);
		//_vm->_saveFileMan->removeSavefile(_vm->getSavegameFilename(999));
		_vm->_unkSceneScreenFlag1 = false;
	}

	return 0;
}
Example #12
0
bool
ProcessNode::setInput(OutputBase& output) {

	return getInput().accept(output);
}
Example #13
0
void
ProcessNode::unsetInput(unsigned int i) {

	return getInput(i).unset();
}
Example #14
0
void
ProcessNode::unsetInput() {

	return getInput().unset();
}
Example #15
0
 virtual void renameSymbol (const Symbol& oldSymbol, const String& newName, const Scope& scope, int recursionDepth)
 {
     for (int i = getNumInputs(); --i >= 0;)
         getInput (i)->renameSymbol (oldSymbol, newName, scope, recursionDepth);
 }
bool CNoiseEstimator::compute() throw()
{
    shared_ptr<ImageType> theInputSPtr = static_pointer_cast<ImageType>( getInput() );
    if ( !checkInput<ImageType>( theInputSPtr, 2, 3 ) )
    {
        return false;
    }
    bModuleReady = true;
    deleteOldOutput();

    uint uiBoxSize = parameters.getUnsignedLong( "Boxsize" );
    double dMean = 0.0;
    double dVariance = 0.0;
    vector<typename ImageType::TDataType> valueVec;
    cerr << theInputSPtr->getExtent(0) << endl;
    cerr << theInputSPtr->getExtent(1) << endl;
    cerr << theInputSPtr->getExtent(2) << endl;
    // Suche Startpunkt. Gehe von Superior abw�ts,
    // bis eine Schicht gefunden wird, in der keine Nullen stehen.
    // Selbiges ist danach fr y und x zu tun
    uint uiStartZ = theInputSPtr->getExtent(2)-1;
    for( uint z = theInputSPtr->getExtent( 2 )-1; z > uiBoxSize; --z )
    {
        for( uint y = 0; y < theInputSPtr->getExtent( 1 ) - uiBoxSize; ++y )
            for( uint x = 0; x < theInputSPtr->getExtent( 0 ) - uiBoxSize; ++x )
                if ( (*theInputSPtr)( x, y, z ) != 0 )
                {
                    uiStartZ = z;
                    z = uiBoxSize;
                }
        cerr << z << endl;
    }
    uint uiStartY = 0;
    uint uiStartX = 0;
    for( uint y = 0; y < theInputSPtr->getExtent( 1 ) - uiBoxSize; ++y )
        for( uint x = 0; x < theInputSPtr->getExtent( 0 ) - uiBoxSize; ++x )
            if ( (*theInputSPtr)( x, y, uiStartZ ) != 0 )
            {
                uiStartY = y;
                uiStartX = x;
                x = theInputSPtr->getExtent(0)-1;
                y = theInputSPtr->getExtent(1)-1;
            }
    for( uint z = uiStartZ; z > uiStartZ - uiBoxSize; --z )
        for( uint y = uiStartY; y < uiStartY + uiBoxSize; ++y )
            for( uint x = uiStartX; x < uiStartX + uiBoxSize; ++x )
            {
                valueVec.push_back( (*theInputSPtr)( x, y, z ) );
            }

    cerr << "Starting at " << uiStartX << ";" << uiStartZ << ";" << uiStartZ << ";" << endl;

    for_each( valueVec.begin(), valueVec.end(),	dMean +=  _1 );
    dMean /= static_cast<double>( valueVec.size() );
    for_each( valueVec.begin(), valueVec.end(),	dVariance += ( _1 - dMean ) * ( _1 - dMean ) );
    dVariance /= static_cast<double>( valueVec.size() );
    dVariance = sqrt( dVariance );

    parameters.setDouble("Mean", dMean/sqrt(static_cast<double>(theInputSPtr->getDataRange().getMaximum())));
    parameters.setDouble("Variance", dVariance/sqrt(static_cast<double>(theInputSPtr->getDataRange().getMaximum())));

    DBG3(  "Absolute: Mean " << dMean << " Variance " << dVariance << endl
           << "Relative: Mean " << dMean/static_cast<double>(theInputSPtr->getDataRange().getMaximum())
           << " Variance " << dVariance/static_cast<double>(theInputSPtr->getDataRange().getMaximum()) );

    return true;
}
Example #17
0
 virtual void visitAllSymbols (SymbolVisitor& visitor, const Scope& scope, int recursionDepth)
 {
     for (int i = getNumInputs(); --i >= 0;)
         getInput(i)->visitAllSymbols (visitor, scope, recursionDepth);
 }
Example #18
0
void Player::update(sf::Time ft, std::vector<sf::Sprite> sprites, std::vector<sf::Sprite> &collectables)
{
	checkForCollisions(sprites, collectables);
	sprite.update(ft);
	getInput(ft);
}
Example #19
0
int MainMenu::handle(int dim) {
	int command = -1;

	uint8 colorMap[16];
	memset(colorMap, 0, sizeof(colorMap));
	_screen->setTextColorMap(colorMap);

	Screen::FontId oldFont = _screen->setFont(_static.font);
	int charWidthBackUp = _screen->_charWidth;

	if (_vm->game() != GI_LOL)
		_screen->_charWidth = -2;
	_screen->setScreenDim(dim);

	int backUpX = _screen->_curDim->sx;
	int backUpY = _screen->_curDim->sy;
	int backUpWidth = _screen->_curDim->w;
	int backUpHeight = _screen->_curDim->h;
	_screen->copyRegion(backUpX, backUpY, backUpX, backUpY, backUpWidth, backUpHeight, 0, 3);

	int x = _screen->_curDim->sx << 3;
	int y = _screen->_curDim->sy;
	int width = _screen->_curDim->w << 3;
	int height =  _screen->_curDim->h;

	drawBox(x, y, width, height, 1);
	drawBox(x + 1, y + 1, width - 2, height - 2, 0);

	int selected = 0;

	draw(selected);

	while (!_screen->isMouseVisible())
		_screen->showMouse();

	int fh = _screen->getFontHeight();
	if (_vm->gameFlags().lang == Common::JA_JPN)
		fh++;

	int textPos = ((_screen->_curDim->w >> 1) + _screen->_curDim->sx) << 3;

	Common::Rect menuRect(x + 16, y + 4, x + width - 16, y + 4 + fh * _static.menuTable[3]);

	while (!_vm->shouldQuit()) {
		updateAnimation();
		bool mousePressed = getInput();

		Common::Point mouse = _vm->getMousePos();
		if (menuRect.contains(mouse)) {
			int item = (mouse.y - menuRect.top) / fh;

			if (item != selected) {
				printString("%s", textPos, menuRect.top + selected * fh, _static.menuTable[5], 0, 5, _static.strings[selected]);
				printString("%s", textPos, menuRect.top + item * fh, _static.menuTable[6], 0, 5, _static.strings[item]);

				selected = item;
			}

			if (mousePressed) {
				for (int i = 0; i < 3; i++) {
					printString("%s", textPos, menuRect.top + selected * fh, _static.menuTable[5], 0, 5, _static.strings[selected]);
					_screen->updateScreen();
					_system->delayMillis(50);
					printString("%s", textPos, menuRect.top + selected * fh, _static.menuTable[6], 0, 5, _static.strings[selected]);
					_screen->updateScreen();
					_system->delayMillis(50);
				}
				command = item;
				break;
			}
		}
		_system->delayMillis(10);
	}

	if (_vm->shouldQuit())
		command = -1;

	_screen->copyRegion(backUpX, backUpY, backUpX, backUpY, backUpWidth, backUpHeight, 3, 0);
	_screen->_charWidth = charWidthBackUp;
	_screen->setFont(oldFont);

	return command;
}
rspfRefPtr<rspfImageData> rspfBandMergeSource::getTile(const rspfIrect& tileRect,
                                              rspf_uint32 resLevel)
{
   rspf_uint32 layerIdx = 0;
   if( ( getNumberOfInputs() == 1) || !isSourceEnabled() )
   {
      return getNextTile(layerIdx, 0, tileRect, resLevel);
   }

   // test if initialized
   if(!theTile.get())
   {
      allocate();
   }
   
   if(!theTile.get())
   {
      return getNextTile(layerIdx, 0, tileRect, resLevel);
   }
   
   long w     = tileRect.width();
   long h     = tileRect.height();
   long tileW = theTile->getWidth();
   long tileH = theTile->getHeight();
   if((w != tileW)||
      (h != tileH))
   {
      theTile->setWidth(w);
      theTile->setHeight(h);
      if((w*h)!=(tileW*tileH))
      {
         theTile->initialize();
      }
      else
      {
         theTile->makeBlank();
      }
   }
   else
   {
      theTile->makeBlank();
   }
   theTile->setOrigin(tileRect.ul());
   rspf_uint32 currentBand = 0;
   rspf_uint32 maxBands = theTile->getNumberOfBands();
   rspf_uint32 inputIdx = 0;
   for(inputIdx = 0; inputIdx < getNumberOfInputs(); ++inputIdx)
   {
      rspfImageSource* input = PTR_CAST(rspfImageSource,
                                                  getInput(inputIdx));
      rspfRefPtr<rspfImageData> currentTile = 0;

      if(input)
      {
         currentTile = input->getTile(tileRect, resLevel);
      }
      else
      {
         currentTile = 0;
      }
      rspf_uint32 maxInputBands = 0;

      if(!currentTile.get())
      {
         maxInputBands = 1;
      }
      else if(currentTile->getNumberOfBands() == 0)
      {
         maxInputBands = 1;
      }
      else
      {
         maxInputBands = currentTile->getNumberOfBands();
      }
      for(rspf_uint32 band = 0;
          ( (band < maxInputBands) &&
            (currentBand < maxBands));
          ++band)
      {
         // clear the band with the actual NULL
         theTile->fill(currentBand, theTile->getNullPix(band));

         if(currentTile.valid())
         {
            if((currentTile->getDataObjectStatus() != RSPF_NULL) &&
               (currentTile->getDataObjectStatus() != RSPF_EMPTY))
            {
               memmove(theTile->getBuf(currentBand),
                       currentTile->getBuf(band),
                       currentTile->getSizePerBandInBytes());
            }
         }
         ++currentBand;
      }
   }
   theTile->validate();

   return theTile;
}
Example #21
0
PlotLine * ExScript::doScript ()
{
  if (proc)
  {
    delete proc;
    proc = 0;
  }

  PlotLine *line = new PlotLine();

  if (! scriptPath.length())
  {
    qDebug("ExScript::calculate: no script path");
    return line;
  }

  proc = new QProcess(this);
  connect(proc, SIGNAL(readyReadStdout()), this, SLOT(readFromStdout()));
  proc->setCommunication(QProcess::Stdin|QProcess::Stdout|QProcess::Stderr);
  proc->addArgument(scriptPath);

  QStringList l = QStringList::split(" ", comlineParms, FALSE);
  int loop;
  for (loop = 0; loop < (int) l.count(); loop++)
    proc->addArgument(l[loop]);

  buffer.truncate(0);

  QString s;
  if (dateFlag || openFlag || highFlag || lowFlag || closeFlag || volumeFlag || oiFlag)
    getInput(s);

  QByteArray ba(s.length());
  if (s.length())
  {
    for (loop = 0; loop < (int) s.length(); loop++)
      ba[loop] = s.at(loop).latin1();
  }

  if (! proc->launch(ba, NULL))
  {
    qDebug("ExScript::calculate: error starting script");
    delete proc;
    proc = 0;
    return line;
  }

  timer->start(seconds * 1000, FALSE);

  wakeup();

  while (proc->isRunning())
  {
    usleep(100);
    wakeup();
  }

  timer->stop();

  if (proc)
  {
    delete proc;
    proc = 0;
  }

  if (! buffer.length())
  {
    qDebug("ExScript::createOutput: output buffer empty");
    return line;
  }

  l = QStringList::split(",", buffer, FALSE);
  for (loop = 0; loop < (int) l.count(); loop++)
    line->append(l[loop].toDouble());

  line->setColor(color);
  line->setType(lineType);
  line->setLabel(label);
  return line;
}
Example #22
0
static int
getCommands (void)
{
  paramLetters ();
  do
    {
      printf ("Command: ");
      getInput ();
      switch (inputBuffer[0])
	{
	case 0:
	  break;
	case 't':
	  do
	    {
	      printf ("Enter the name of a table: ");
	      getInput ();
	      strcpy (table, inputBuffer);
	    }
	  while ((validTable = lou_getTable (table)) == NULL);
	  break;
	case 'r':
	  if (validTable == NULL)
	    {
	      printf ("You must enter a valid table name.\n");
	      inputBuffer[0] = 0;
	    }
	  break;
	case 'm':
	  printf ("Reset mode");
	  if (getYN ())
	    mode = 0;
	  printf ("No contractions");
	  mode |= getYN ();
	  printf ("Computer braille at cursor");
	  mode |= 2 * getYN ();
	  printf ("Dots input and output");
	  mode |= 4 * getYN ();
	  printf ("8-dot computer braille");
	  mode |= 8 * getYN ();
	  printf ("Pass1 only");
	  mode |= 16 * getYN ();
	  break;
	case 'l':
	  printf ("Do you want to test input and output lengths");
	  showSizes = getYN ();
	  if (!showSizes)
	    {
	      outputSize = BUFSIZE;
	      break;
	    }
	  printf ("Enter a maximum output size: ");
	  getInput ();
	  outputSize = atoi (inputBuffer);
	  if (outputSize < 0 || outputSize > BUFSIZE)
	    {
	      printf ("Output size must be from 0 tu %d.\n", BUFSIZE);
	      outputSize = BUFSIZE;
	      showSizes = 0;
	    }
	  break;
	case 'c':
	  printf ("Enter a cursor position: ");
	  getInput ();
	  enteredCursorPos = atoi (inputBuffer);
	  if (enteredCursorPos < -1 || enteredCursorPos > outputSize)
	    {
	      printf ("Cursor position must be from -1 to %d.\n", outputSize);
	      enteredCursorPos = -1;
	    }
	  break;
	case 'e':
	  printf ("(Enter an x to cancel emphasis.)\n");
	  printf ("Enter an emphasis string: ");
	  getInput ();
	  strcpy (enteredEmphasis, inputBuffer);
	  break;
	case 's':
	  printf ("(Enter an x to cancel spacing.)\n");
	  printf ("Enter a spacing string: ");
	  getInput ();
	  strcpy (enteredSpacing, inputBuffer);
	  break;
	case 'h':
	  printf ("Commands: action\n");
	  printf ("(t)able: Enter a table name\n");
	  printf ("(r)un: run the translation/back-translation loop\n");
	  printf ("(m)ode: Enter a mode parameter\n");
	  printf ("(c)ursor: Enter a cursor position\n");
	  printf ("(e)mphasis: Enter an emphasis string\n");
	  printf ("(s)pacing: Enter a spacing string\n");
	  printf ("(h)elp: print this page\n");
	  printf ("(q)uit: leave the program\n");
	  printf ("(f)orward-only: do only forward translation\n");
	  printf ("(b)ack-only: do only back-translation\n");
	  printf ("show-(p)ositions: show input and output positions\n");
	  printf
	    ("m(i)nimal: test translator and back-translator with minimal parameters\n");
	  printf ("test-(l)engths: test accuracy of returned lengths\n");
	  printf ("\n");
	  paramLetters ();
	  break;
	case 'q':
	  lou_free();
	  exit (EXIT_SUCCESS);
	case 'f':
	  printf ("Do only forward translation");
	  forwardOnly = getYN ();
	  break;
	case 'b':
	  printf ("Do only backward translation");
	  backOnly = getYN ();
	  break;
	case 'p':
	  printf ("Show input and output positions");
	  showPositions = getYN ();
	  break;
	case 'i':
	  printf
	    ("Test translation/back-translation loop with minimal parameters");
	  minimalist = getYN ();
	  break;
	default:
	  printf ("Bad choice.\n");
	  break;
	}
      if (forwardOnly && backOnly)
	printf
	  ("You cannot specify both forward-only and backward-only translation.\n");
    }
  while (inputBuffer[0] != 'r');
  return 1;
}
int Polylists2lines::execute()
{
	bool verbose = false;
	getBoolOption("v", verbose);
	int error = 0;

	// How many geometry elements are there?
	int geometryElementCount = (int)(_dae->getDatabase()->getElementCount(NULL, "geometry", getInput(0).c_str()));
//	if(verbose)	cerr<<"There are "<<geometryElementCount<<" geometry elements in this file\n"; 

	for(int currentGeometry = 0; currentGeometry < geometryElementCount; currentGeometry++)
	{
		// Find the next geometry element
		domGeometry *thisGeometry;
		error = _dae->getDatabase()->getElement((daeElement**)&thisGeometry,currentGeometry, NULL, "geometry", getInput(0).c_str());

		// Get the mesh out of the geometry
		domMesh *thisMesh = thisGeometry->getMesh();
		if (thisMesh == 0) continue;

		// Loop over all the polygon elements
		daeUInt PolylistsCount = (daeUInt) thisMesh->getPolylist_array().getCount();

//		polylists
		for(daeUInt j=0; j<PolylistsCount; j++)
		{
			// Get the polygons out of the mesh
			// Always get index 0 because every pass through this loop deletes the <polygons> element as it finishes with it
			domPolylist *polylist = thisMesh->getPolylist_array()[0];
			
			domLines *thisLines = (domLines *)thisMesh->createAndPlace("lines");
			domP*  lineP = (domP*) thisLines->createAndPlace("p");

			// add inputs
			unsigned int offsetcount = 0;
			for(unsigned int i=0; i<polylist->getInput_array().getCount(); i++)
			{
				unsigned int tempoffset = (unsigned int)polylist->getInput_array()[i]->getOffset();
				if (offsetcount < tempoffset) offsetcount = tempoffset;
				thisLines->placeElement( polylist->getInput_array()[i]->clone() );
			}
			offsetcount++; //offset is 1 start
			// add names
			if (polylist->getName())
				thisLines->setName(polylist->getName());
			// set materials
			thisLines->setMaterial(polylist->getMaterial());

			// set Ps
			domListOfUInts vcount = polylist->getVcount()->getValue();
			domListOfUInts p = polylist->getP()->getValue();
			
			unsigned int linecount = 0;

			for (daeUInt k=0; k<vcount.getCount(); k++)
			{
				unsigned int vertexcount = (unsigned int) vcount[k];
				for (daeUInt m=0; m<vertexcount-1; m++)
				{
					for (unsigned int o=0; o<offsetcount; o++)
						lineP->getValue().append( p[(linecount+m)*offsetcount+o]);
					for (unsigned int o=0; o<offsetcount; o++)
						lineP->getValue().append( p[(linecount+m+1)*offsetcount+o]);
				}
				for (unsigned int o=0; o<offsetcount; o++)
					lineP->getValue().append( p[(linecount+vertexcount-1)*offsetcount+o]);
				for (unsigned int o=0; o<offsetcount; o++)
					lineP->getValue().append( p[linecount*offsetcount+ o]);
				linecount += vertexcount;
			}
			thisLines->setCount(linecount);
			thisMesh->removeChildElement(polylist);
		}
	}
	return 0;
}
Example #24
0
int
main (int argc, char **argv)
{
  char *charbuf;
  widechar inbuf[BUFSIZE];
  widechar transbuf[BUFSIZE];
  widechar outbuf[BUFSIZE];
  int outputPos[BUFSIZE];
  int inputPos[BUFSIZE];
  int inlen;
  int translen;
  int outlen;
  int cursorPos = -1;
  int realInlen = 0;
  int k;
  int optc;

  set_program_name (argv[0]);

  while ((optc = getopt_long (argc, argv, "hv", longopts, NULL)) != -1)
    switch (optc)
      {
      /* --help and --version exit immediately, per GNU coding standards.  */
      case 'v':
        version_etc (stdout, program_name, PACKAGE_NAME, VERSION, AUTHORS, (char *) NULL);
        exit (EXIT_SUCCESS);
        break;
      case 'h':
        print_help ();
        exit (EXIT_SUCCESS);
        break;
      default:
	fprintf (stderr, "Try `%s --help' for more information.\n",
		 program_name);
	exit (EXIT_FAILURE);
        break;
      }

  if (optind < argc)
    {
      /* Print error message and exit.  */
      fprintf (stderr, "%s: extra operand: %s\n",
	       program_name, argv[optind]);
      fprintf (stderr, "Try `%s --help' for more information.\n",
               program_name);
      exit (EXIT_FAILURE);
    }

  validTable = NULL;
  enteredCursorPos = -1;
  mode = 0;
  while (1)
    {
      getCommands ();
      printf ("Type something, press enter, and view the results.\n");
      printf ("A blank line returns to command entry.\n");
      if (minimalist)
	while (1)
	  {
	    translen = outputSize;
	    outlen = outputSize;
	    inlen = getInput ();
	    if (inlen == 0)
	      break;
	    if (!(realInlen = extParseChars (inputBuffer, inbuf)))
	      break;
	    inlen = realInlen;
	    if (!lou_translateString (table, inbuf, &inlen, transbuf,
				      &translen, NULL, NULL, 0))
	      break;
	    transbuf[translen] = 0;
	    printf ("Translation:\n");
	    charbuf = showString (transbuf, translen);
	    k = strlen (charbuf) - 1;
	    charbuf[k] = 0;
	    printf ("%s\n", &charbuf[1]);
	    if (showSizes)
	      printf ("input length = %d; output length = %d\n", inlen,
		      translen);
	    lou_backTranslateString (table, transbuf, &translen, outbuf,
				     &outlen, NULL, NULL, 0);
	    printf ("Back-translation:\n");
	    charbuf = showString (outbuf, outlen);
	    k = strlen (charbuf) - 1;
	    charbuf[k] = 0;
	    printf ("%s\n", &charbuf[1]);
	    if (showSizes)
	      printf ("input length = %d; output length = %d.\n", translen,
		      outlen);
	    if (outlen == realInlen)
	      {
		for (k = 0; k < realInlen; k++)
		  if (inbuf[k] != outbuf[k])
		    break;
		if (k == realInlen)
		  printf ("Perfect roundtrip!\n");
	      }
	  }
      else
	while (1)
	  {
	    for (k = 0; k < strlen (enteredEmphasis); k++)
	      emphasis[k] = (formtype) enteredEmphasis[k];
	    emphasis[k] = 0;
	    strcpy (spacing, enteredSpacing);
	    cursorPos = enteredCursorPos;
	    inlen = getInput ();
	    if (inlen == 0)
	      break;
	    outlen = outputSize;
	    if (backOnly)
	      {
	    if (!(translen = extParseChars (inputBuffer, transbuf)))
	      break;
	    inlen = realInlen;
	      }
	    else
	      {
		translen = outputSize;
	    if (!(realInlen = extParseChars (inputBuffer, inbuf)))
	      break;
	    inlen = realInlen;
		if (!lou_translate (table, inbuf, &inlen, transbuf,
				    &translen, emphasis, spacing,
				    &outputPos[0], &inputPos[0], &cursorPos,
				    mode))
		  break;
		transbuf[translen] = 0;
		if (mode & dotsIO)
		  {
		    printf ("Translation dot patterns:\n");
		    printf ("%s\n", showDots (transbuf, translen));
		  }
		else
		  {
		    printf ("Translation:\n");
		    charbuf = showString (transbuf, translen);
		    k = strlen (charbuf) - 1;
		    charbuf[k] = 0;
		    printf ("%s\n", &charbuf[1]);
		    if (showSizes)
		      printf ("input length = %d; output length = %d\n",
			      inlen, translen);
		  }
	      }
	    if (cursorPos != -1)
	      printf ("Cursor position: %d\n", cursorPos);
	    if (enteredSpacing[0])
	      printf ("Returned spacing: %s\n", spacing);
	    if (showPositions)
	      {
		printf ("Output positions:\n");
		for (k = 0; k < inlen; k++)
		  printf ("%d ", outputPos[k]);
		printf ("\n");
		printf ("Input positions:\n");
		for (k = 0; k < translen; k++)
		  printf ("%d ", inputPos[k]);
		printf ("\n");
	      }
	    if (!forwardOnly)
	      {
		if (!lou_backTranslate (table, transbuf, &translen,
					outbuf, &outlen,
					emphasis, spacing, &outputPos[0],
					&inputPos[0], &cursorPos, mode))
		  break;
		printf ("Back-translation:\n");
		charbuf = showString (outbuf, outlen);		k = 
		strlen (charbuf) - 1;
		charbuf[k] = 0;
		printf ("%s\n", &charbuf[1]);
		if (showSizes)
		  printf ("input length = %d; output length = %d\n",
			  translen, outlen);
		if (cursorPos != -1)
		  printf ("Cursor position: %d\n", cursorPos);
		if (enteredSpacing[0])
		  printf ("Returned spacing: %s\n", spacing);
		if (showPositions)
		  {
		    printf ("Output positions:\n");
		    for (k = 0; k < translen; k++)
		      printf ("%d ", outputPos[k]);
		    printf ("\n");
		    printf ("Input positions:\n");
		    for (k = 0; k < outlen; k++)
		      printf ("%d ", inputPos[k]);
		    printf ("\n");
		  }
	      }
	    if (!(forwardOnly || backOnly))
	      {
		if (outlen == realInlen)
		  {
		    for (k = 0; k < realInlen; k++)
		      if (inbuf[k] != outbuf[k])
			break;
		    if (k == realInlen)
		      printf ("Perfect roundtrip!\n");
		  }
	      }
	  }
    }
  lou_free ();
  exit (EXIT_SUCCESS);
}
Example #25
0
File: msn.c Project: nupfel/r0ket
/*Message Receiver*/
void waitMsg()
{
    uint8_t key;
    unsigned char buf[32];
    char sender_nick[10];
    int n,i;
    int index=0;
    int rcv =0;
    int try=0;
    do
    {
        key = getInput();
        if(1)
        {
            nrf_config_set(&config);
            n = nrf_rcv_pkt_time(100,32,buf);
            getInputWaitTimeout(100);
            if(n == 32)
            {
                index=buf[0];
                for(i=0; i<10; i++)
                    sender_nick[i]=buf[i+1];
                lcdClear();
                lcdPrintln("");
                lcdPrintln("CCC MSN 0.1b");
                lcdPrintln("---------------");
                lcdPrintln(msgs[index]);
                lcdPrintln("");
                lcdPrintln("Received");
                lcdPrintln("");
                lcdPrintln("_______________");
                lcdPrintln(sender_nick);
                lcdRefresh();
                blink();
                rcv=1;
                try=0;
            } else if(rcv)
            {
                lcdClear();
                lcdPrintln("");
                lcdPrintln("CCC MSN 0.1b");
                lcdPrintln("-----------------");
                lcdPrintln("Waiting...");
                lcdPrint("Try ");
                lcdPrintln(IntToStr(try,5,0));
                lcdPrintln("");
                lcdPrintln(msgs[index]);
                lcdPrintln("_______________");
                lcdPrintln(sender_nick);
                lcdRefresh();
            }
            try++;
        }
        if(!rcv)
        {
            lcdClear();
            lcdPrintln("");
            lcdPrintln("CCC MSN 0.1b");
            lcdPrintln("-----------------");
            lcdPrintln("Waiting...");
            lcdPrintln("");
            lcdPrint("Try ");
            lcdPrintln(IntToStr(try,5,0));
            lcdPrintln("");
            lcdPrintln("_______________");
            lcdPrintln("W8 Users Auto");
            lcdRefresh();
        }
uint32_t AudioRecord::getInputFramesLost() const
{
    // no need to check mActive, because if inactive this will return 0, which is what we want
    return AudioSystem::getInputFramesLost(getInput());
}
Example #27
0
static void GUINewMode(void)
{
  int Max, Sel, Dis;
  char* buffer;
  char* arg1 = getRecord();
  char* arg2 = getAuthor();
  char* arg3 = getCopyright();
  char* arg4 = getDriver();
  char* arg5 = getVersion();
  char* arg6 = getAnnotation();

  buffer = AllocVec( strlen( arg1 ) +
                     strlen( arg2 ) +
                     strlen( arg3 ) +
                     strlen( arg4 ) +
                     strlen( arg5 ) +
                     strlen( arg6 ) +
                     128,
                     MEMF_ANY);

  if( buffer != NULL )
  {
    sprintf( buffer,"0x%08lx\n%s\n%s\n%s\nDevs:AHI/%s.audio\n%s\n%s",
      getAudioMode(),
      arg1,
      arg2,
      arg3,
      arg4,
      arg5,
      arg6 );

    set(MUIInfos, MUIA_Text_Contents, (ULONG) buffer);

    FreeVec(buffer);
  }

  Max = max(state.Frequencies -1, 0);
  Sel = min(Max, state.FreqSelected);
  Dis = Max==0;
  set(MUIFreq, MUIA_Disabled, Dis);
  if( !Dis )
  {
    set(MUIFreq, MUIA_Numeric_Max, Max);
    set(MUIFreq, MUIA_Numeric_Value, Sel);
  }
  set(MUILFreq, MUIA_Text_Contents, (ULONG) getFreq());

  Max = max(state.Channels, 0);
  Sel = min(Max, state.ChannelsSelected);
  Dis = (Max == 0 || Max == 1) || state.ChannelsDisabled;
  set(MUIChannels, MUIA_Disabled, Dis);
  if( !Dis )
  {
    set(MUIChannels, MUIA_Numeric_Max, Max);
    set(MUIChannels, MUIA_Numeric_Value, Sel);
  }
  set(MUILChannels, MUIA_Text_Contents, (ULONG) getChannels());

  Max = max(state.OutVols -1, 0);
  Sel = min(Max, state.OutVolSelected);
  Dis = Max==0;
  set(MUIOutvol, MUIA_Disabled, Dis);
  if( !Dis )
  {
    set(MUIOutvol, MUIA_Numeric_Max, Max);
    set(MUIOutvol, MUIA_Numeric_Value, Sel);
  }
  set(MUILOutvol, MUIA_Text_Contents, (ULONG) getOutVol());

  Max = max(state.MonVols -1, 0);
  Sel = min(Max, state.MonVolSelected);
  Dis = Max==0;
  set(MUIMonvol, MUIA_Disabled, Dis);
  if( !Dis )
  {
    set(MUIMonvol, MUIA_Numeric_Max, Max);
    set(MUIMonvol, MUIA_Numeric_Value, Sel);
  }
  set(MUILMonvol, MUIA_Text_Contents, (ULONG) getMonVol());

  Max = max(state.Gains -1, 0);
  Sel = min(Max, state.GainSelected);
  Dis = Max==0;
  set(MUIGain, MUIA_Disabled, Dis);
  if( !Dis )
  {
    set(MUIGain, MUIA_Numeric_Max, Max);
    set(MUIGain, MUIA_Numeric_Value, Sel);
  }
  set(MUILGain, MUIA_Text_Contents, (ULONG) getGain());

  Max = max(state.Inputs -1, 0);
  Sel = min(Max, state.InputSelected);
  Dis = Max==0;
  set(MUIInput, MUIA_Disabled, Dis);
  if( !Dis )
  {
    set(MUIInput, MUIA_Numeric_Max, Max);
    set(MUIInput, MUIA_Numeric_Value, Sel);
  }
  set(MUILInput, MUIA_Text_Contents, (ULONG) getInput());

  Max = max(state.Outputs -1, 0);
  Sel = min(Max, state.OutputSelected);
  Dis = Max==0;
  set(MUIOutput, MUIA_Disabled, Dis);
  if( !Dis )
  {
    set(MUIOutput, MUIA_Numeric_Max, Max);
    set(MUIOutput, MUIA_Numeric_Value, Sel);
  }
  set(MUILOutput, MUIA_Text_Contents, (ULONG) getOutput());


  set(MUIPlay, MUIA_Disabled, getAudioMode() == AHI_INVALID_ID);
}
Example #28
0
BOOL CALLBACK DlgConsoleProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
	switch(Message)
	{
		case WM_INITDIALOG:			
			hDialogHwnd = hwnd;
			RegisterHotKey(hwnd, TOGGLE, MOD_CONTROL | MOD_ALT, 'Z');
			GetAllWindow();
			Cout("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
		break;

		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case IDOK:
					CHAR text[4068], list[4068];
					Clear();
					getInput(text);
					//console(text);
					//UpdateConsole();
					WindowsList.getSimilarIdList(text, list);
					// Cout(list);
					UpdateConsole();
				break;
			}
		break;

		case WM_HOTKEY:
			//char text[50];
			//wsprintf(text, "wParam: %x  lParam:%x", wParam, lParam);
			//MessageBox(hwnd, text, NULL, MB_OK);
			switch(wParam)
			{
			case TOGGLE:
				if (flag)
				{
					ShowWindow(hDialogHwnd, SW_HIDE);
					flag = 0;
				}else{
					ShowWindow(hDialogHwnd, SW_SHOW);
					SetFocus(GetDlgItem(hDialogHwnd, IDC_EDIT_LINE));
					flag = 1;
				}
				break;
			}
			break;

		case WM_MOUSEMOVE:
			echo("hello key down");
			break;

		case WM_SETFOCUS:
			// MessageBox(hwnd, (LPCSTR)"WM_SETFOCUS", NULL, MB_OK);
		break;

		case WM_CLOSE:
			EndDialog(hwnd, 0);
			break;
		
		case WM_DESTROY:
			FreeLibrary(hRichEdit);		
			PostQuitMessage(0);
		break;

		default:
			return DefWindowProc(hwnd, Message, wParam, lParam);
	}
	return TRUE;
}
Example #29
0
void CloneMeshOperator::process(int tick)
{
    if (mesh != 0)
        delete mesh;

    unsigned char clones = getByteProperty(0);
    D3DXVECTOR3 scaleVector = getVectorProperty(1);
    D3DXVECTOR3 rotationVector = getVectorProperty(2);
    D3DXVECTOR3 translationVector = getVectorProperty(3);
    D3DXMATRIX scaleMatrix;
    D3DXMatrixScaling(&scaleMatrix,
                      scaleVector.x,
                      scaleVector.y,
                      scaleVector.z);
    D3DXMATRIX rotationXMatrix;
    D3DXMatrixRotationX(&rotationXMatrix, rotationVector.x);
    D3DXMATRIX rotationYMatrix;
    D3DXMatrixRotationY(&rotationYMatrix, rotationVector.y);
    D3DXMATRIX rotationZMatrix;
    D3DXMatrixRotationZ(&rotationZMatrix, rotationVector.z);
    D3DXMATRIX translationMatrix;
    D3DXMatrixTranslation(&translationMatrix,
                          translationVector.x,
                          translationVector.y,
                          translationVector.z);
    D3DXMATRIX cloneMatrix = scaleMatrix * rotationXMatrix * rotationYMatrix * rotationZMatrix * translationMatrix;

    Mesh* srcMesh = getInput(0)->mesh;

    mesh = new Mesh(srcMesh->getNumVertices() * clones,
                    srcMesh->getNumTriangles() * clones,
                    srcMesh->getNumQuads() * clones);

    D3DXMATRIX matrix;
    D3DXMatrixIdentity(&matrix);

    int c = 0;
    int verticeOffset = 0;
    int triangleIndex = 0;
    int quadIndex = 0;
    do
    {
        c++;
        for (int v = 0; v < srcMesh->getNumVertices(); v++)
        {
            Vec3 pos = srcMesh->pos(v);
            Vec3 transformedPos;
            D3DXVec3TransformCoord(&transformedPos, &pos, &matrix);
            mesh->pos(verticeOffset + v) = transformedPos;
            mesh->uv(verticeOffset + v) = srcMesh->uv(v);
        }

        for (int f = 0; f < srcMesh->getNumFaces(); f++)
        {
            int n;
            int* face = srcMesh->face(f, n);

            if (n == 3)
            {
                mesh->setTriangle(triangleIndex,
                                  verticeOffset + face[0],
                                  verticeOffset + face[1],
                                  verticeOffset + face[2]);
                triangleIndex++;
            }
            else
            {
                mesh->setQuad(quadIndex,
                              verticeOffset + face[0],
                              verticeOffset + face[1],
                              verticeOffset + face[2],
                              verticeOffset + face[3]);
                quadIndex++;
            }
        }

        verticeOffset += srcMesh->getNumVertices();
        matrix *= cloneMatrix;
    }
    while (c < clones);
}
Example #30
0
bool
ProcessNode::setInput(unsigned int i, boost::shared_ptr<Data> data) {

	return getInput(i).accept(data);
}