Esempio n. 1
0
void closedoor()
{
	int i;

	/* can't find objects is time is stopped*/
	if (c[TIMESTOP])  return;	

	showcell(playerx,playery);  
	cursors();  
	yrepcount=0;

	i=item[playerx][playery];	
	if (i != OOPENDOOR) {
		lprcat("\nThere is no open door here.");
		return;
	}
	lprcat("\nThe door closes.");
	forget();
	item[playerx][playery]=OCLOSEDDOOR;
	iarg[playerx][playery]=0;
	dropflag=1; /* So we won't be asked to open it */
/*	playerx = lastpx;  
	playery = lastpy;*/
		/* if there is now a monster on the space we 
		** need to move back on to, get rid of it */
/*	if (mitem[lastpx][lastpy].mon) {
		lprintf("\nThe %s disappears mysteriously.",
			monster[mitem[lastpx][lastpy].mon].name);
		disappear(lastpx, lastpy);
		hitp[lastpx][lastpy]=0;
		}*/
}
Esempio n. 2
0
File: CCA.c Progetto: alekstorm/tala
TableOfReal CCA_and_TableOfReal_scores (CCA me, TableOfReal thee, long numberOfFactors)
{
	TableOfReal him = NULL;
	long n = thy numberOfRows;
	long nx = my x -> dimension, ny = my y -> dimension;

	if (ny + nx != thy numberOfColumns) return Melder_errorp7 (L"The number "
		"of columns in the table (", Melder_integer (thy numberOfColumns), L") does not agree with "
		"the dimensions of the CCA object (ny + nx = ", Melder_integer (ny), L" + ", Melder_integer (nx), L").");

	if (numberOfFactors == 0) numberOfFactors = my numberOfCoefficients;
	if (numberOfFactors < 1 || numberOfFactors > my numberOfCoefficients)
		return Melder_errorp3 (L"The number of factors must be in interval "
			"[1, ", Melder_integer (my numberOfCoefficients), L"].");
	
	him = TableOfReal_create (n, 2 * numberOfFactors);
	if (him == NULL) return NULL;

	if (! NUMstrings_copyElements (thy rowLabels, his rowLabels, 1, thy numberOfRows) ||
		! Eigen_and_TableOfReal_project_into (my y, thee, 1, ny, &him, 1, numberOfFactors) ||
		! Eigen_and_TableOfReal_project_into (my x, thee, ny + 1,
			thy numberOfColumns, &him, numberOfFactors + 1, his numberOfColumns) ||
		! TableOfReal_setSequentialColumnLabels (him, 1, numberOfFactors, L"y_", 1, 1) ||
		! TableOfReal_setSequentialColumnLabels (him, numberOfFactors + 1,
			his numberOfColumns, L"x_", 1, 1)) forget (him);

	return him;
}
Categories FFNet_Activation_to_Categories (FFNet me, Activation activation, int labeling)
{
	Categories thee = NULL, categories = my outputCategories;
	long i, (*labelingFunction) (I, const double act[]);
	
	if (! my outputCategories)
	{
		(void) Melder_error1 (L"FFNet & Activation: To Categories\n");
		return Melder_errorp1 (L"The neural net has no Categories (has the FFNet been trained yet?).");
	}
	if (my nOutputs != activation->nx)
	{
		(void) Melder_error1 (L"FFNet & Activation: To Categories\n");
		return Melder_errorp1 (L"The number of columns in the Activation must equal the number of outputs of FFNet.");
	}
	thee = Categories_create ();
	if (thee == NULL) return NULL;
	labelingFunction = labeling == 2 ? stochastic : winnerTakesAll;
	for (i = 1; i <= activation->ny; i++)
	{
		long index = labelingFunction (me, activation->z[i]);
		Data item = Data_copy (categories->item[index]);
		if (item == NULL || ! Collection_addItem (thee, item)) 
		{
			forget (thee);
			return Melder_errorp3 (L"FFNet & Activation: To Categories\n\nError creating label ",
				Melder_integer (i), L".");
		}
	}
	return thee;
}
Esempio n. 4
0
Sound Sound_upsample (Sound me) {
	double *data = NULL;
	Sound thee = NULL;

	long nfft = 1;
	while (nfft < my nx + 2000) nfft *= 2;
	thee = Sound_create (my ny, my xmin, my xmax, my nx * 2, my dx / 2, my x1); cherror
	data = NUMdvector (1, 2 * nfft); cherror
	for (long channel = 1; channel <= my ny; channel ++) {
		NUMdvector_copyElements (my z [channel], data + 1000, 1, my nx);
		NUMrealft (data, nfft, 1); cherror
		long imin = (long) (nfft * 0.95);
		for (long i = imin + 1; i <= nfft; i ++) {
			data [i] *= ((double) (nfft - i)) / (nfft - imin);
		}
		data [2] = 0.0;
		NUMrealft (data, 2 * nfft, -1); cherror
		double factor = 1.0 / nfft;
		for (long i = 1; i <= thy nx; i ++) {
			thy z [channel] [i] = data [i + 2000] * factor;
		}
	}
end:
	NUMdvector_free (data, 1);
	iferror forget (thee);
	return thee;
}
Esempio n. 5
0
static void menu_cb_runSelection (EDITOR_ARGS) {
	EDITOR_IAM (ScriptEditor);
	if (my interpreter -> running)
		Melder_throw (U"The script is already running (paused). Please close or continue the pause or demo window.");
	autostring32 text = GuiText_getSelection (my textWidget);
	if (text.peek() == NULL)
		Melder_throw (U"No text selected.");
	structMelderFile file = { 0 };
	if (my name [0]) {
		Melder_pathToFile (my name, & file);
		MelderFile_setDefaultDir (& file);
	}
	Melder_includeIncludeFiles (& text);
	int npar = Interpreter_readParameters (my interpreter, text.peek());
	if (npar) {
		/*
		 * Pop up a dialog box for querying the arguments.
		 */
		forget (my argsDialog);
		my argsDialog = Interpreter_createForm (my interpreter, my d_windowForm, NULL, args_ok_selectionOnly, me, true);
		UiForm_do (my argsDialog, false);
	} else {
		autoPraatBackground background;
		if (my name [0]) MelderFile_setDefaultDir (& file);
		Interpreter_run (my interpreter, text.peek());
	}
}
Esempio n. 6
0
//------------------------------------------------------------------------
void CTextEdit::platformLooseFocus (bool returnPressed)
{
	remember ();
	bWasReturnPressed = returnPressed;
	getFrame ()->setFocusView (0);
	forget ();
}
Esempio n. 7
0
	void _GuiMacScale_destroy (GuiObject widget) {
		_GuiMac_clipOnParent (widget);
		EraseRect (& widget -> rect);
		GuiMac_clipOff ();
		iam_scale;
		forget (me);   // NOTE: my widget is not destroyed here
	}
Esempio n. 8
0
static void initScreen (HyperPage me) {
	my d_y = PAGE_HEIGHT + my top / 5.0;
	my d_x = 0;
	my previousBottomSpacing = 0.0;
	forget (my links);
	my links = Collection_create (classHyperLink, 100);
}
Distributions Transition_to_Distributions_conflate (Transition me) {
	Distributions thee = NULL;
//start:
	thee = Distributions_create (my numberOfStates, 1); cherror

	/*
	 * Copy labels.
	 */
	for (long i = 1; i <= my numberOfStates; i ++) {
		thy rowLabels [i] = Melder_wcsdup_e (my stateLabels [i]); cherror
	}

	/*
	 * Average rows.
	 */
	for (long i = 1; i <= my numberOfStates; i ++) {
		for (long j = 1; j <= my numberOfStates; j ++)
			thy data [i] [1] += my data [j] [i];
		thy data [i] [1] /= my numberOfStates;
	}

end:
	iferror {
		forget (thee);
		return (structDistributions *)Melder_errorp ("(Transition_to_Distributions_conflate:) Not performed.");
	}
	return thee;
}
Esempio n. 10
0
PointProcess Sound_Pitch_to_PointProcess_peaks (Sound sound, Pitch pitch, int includeMaxima, int includeMinima) {
	PointProcess point = PointProcess_create (sound -> xmin, sound -> xmax, 10);
	double t = pitch -> xmin;
	double addedRight = -1e300;
	/*
	 * Cycle over all voiced intervals.
	 */

	for (;;) {
		double tleft, tright, tmiddle, f0middle, tmax, tsave;
		if (! Pitch_getVoicedIntervalAfter (pitch, t, & tleft, & tright)) break;
		/*
		 * Go to the middle of the voiced interval.
		 */
		tmiddle = (tleft + tright) / 2;
		if (! Melder_progress1 ((tmiddle - sound -> xmin) / (sound -> xmax - sound -> xmin), L"Sound & Pitch to PointProcess"))
			goto end;
		f0middle = Pitch_getValueAtTime (pitch, tmiddle, kPitch_unit_HERTZ, Pitch_LINEAR);

		/*
		 * Our first point is near this middle.
		 */
		Melder_assert (NUMdefined (f0middle));
		tmax = Sound_findExtremum (sound, tmiddle - 0.5 / f0middle, tmiddle + 0.5 / f0middle, includeMaxima, includeMinima);
		Melder_assert (NUMdefined (tmax));
		if (! PointProcess_addPoint (point, tmax)) goto end;

		tsave = tmax;
		for (;;) {
			double f0 = Pitch_getValueAtTime (pitch, tmax, kPitch_unit_HERTZ, Pitch_LINEAR);
			if (f0 == NUMundefined) break;
			tmax = Sound_findExtremum (sound, tmax - 1.25 / f0, tmax - 0.8 / f0, includeMaxima, includeMinima);
			if (tmax < tleft) {
				if (tmax - addedRight > 0.8 / f0)
					if (! PointProcess_addPoint (point, tmax)) goto end;
				break;
			}
			if (tmax - addedRight > 0.8 / f0)   /* Do not fill in a short originally unvoiced interval twice. */
				if (! PointProcess_addPoint (point, tmax)) goto end;
		}
		tmax = tsave;
		for (;;) {
			double f0 = Pitch_getValueAtTime (pitch, tmax, kPitch_unit_HERTZ, Pitch_LINEAR);
			if (f0 == NUMundefined) break;
			tmax = Sound_findExtremum (sound, tmax + 0.8 / f0, tmax + 1.25 / f0, includeMaxima, includeMinima);
			if (tmax > tright) {
				if (! PointProcess_addPoint (point, tmax)) goto end;
				addedRight = tmax;
				break;
			}
			if (! PointProcess_addPoint (point, tmax)) goto end;
			addedRight = tmax;
		}
		t = tright;
	}
end:
	Melder_progress1 (1.0, NULL);
	iferror forget (point);
	return point;
}
Distributions Distributions_Transition_map (Distributions me, Transition map) {
	Distributions thee = NULL;

	/*
	 * Preconditions: matrix matching.
	 */
	if (map -> numberOfStates != my numberOfRows)
		error5 (L"Number of data (", Melder_integer (map -> numberOfStates), L") in mapping matrix "
			"does not match number of data (", Melder_integer (my numberOfRows), L") in distribution.")

	/*
	 * Create the output object.
	 */
	thee = (structDistributions *)Data_copy (me); cherror

	/*
	 * Compute the elements of the surface distributions.
	 */
	for (long row = 1; row <= my numberOfRows; row ++) for (long col = 1; col <= my numberOfColumns; col ++) {
		thy data [row] [col] = 0.0;
		for (long m = 1; m <= map -> numberOfStates; m ++)
			thy data [row] [col] += my data [m] [col] * map -> data [m] [row];
	}

end:
	iferror {
		forget (thee);
		return (structDistributions *)Melder_errorp1 (L"Distributions & Transition: Mapping not performed.");
	}
	return thee;
}
Esempio n. 12
0
int KNN_prune_noisy
(
    ///////////////////////////////
    // Parameters                //
    ///////////////////////////////

    Pattern p,      // source
    //
    Categories c,   // source
    //
    long y,         // source instance index
    //
    long k          // k(!)
    //
)

{
    if (y > p->ny) y = p->ny;   // safety belt
    if (k > p->ny) k = p->ny;

    FeatureWeights fws = FeatureWeights_create(p->nx);
    if (fws)
    {
        long *indices = NUMlvector (0, p->ny - 1);    // the coverage is not bounded by k but by n
        // long reachability = KNN_kNeighboursSkip(p, p, fws, y, k, indices, 0); .OS.081011
        long reachability = KNN_kNeighboursSkip(p, p, fws, y, k, indices, y);
        long coverage = KNN_prune_kCoverage(p, c, y, k, indices);

        NUMlvector_free (indices, 0);
        forget(fws);
        if (!KNN_prune_superfluous(p, c, y, k, 0) && reachability > coverage)
            return(1);
    }
    return(0);
}
Esempio n. 13
0
Sound Sounds_combineToStereo (Sound me, Sound thee) {
	if (my ny != 1 || thy ny != 1) return (structSound *)Melder_errorp ("Can only combine mono sounds. Stereo sound not created.");
	if (my dx != thy dx) return (structSound *)Melder_errorp ("Sampling frequencies do not match. Sounds not combined.");
	double dx = my dx;   // or thy dx, which is the same
	double xmin = my xmin < thy xmin ? my xmin : thy xmin;
	double xmax = my xmax > thy xmax ? my xmax : thy xmax;
	long myInitialZeroes = floor ((my xmin - xmin) / dx);
	long thyInitialZeroes = floor ((thy xmin - xmin) / dx);
	double myx1 = my x1 - my dx * myInitialZeroes;
	double thyx1 = thy x1 - thy dx * thyInitialZeroes;
	double x1 = 0.5 * (myx1 + thyx1);
	long mynx = my nx + myInitialZeroes;
	long thynx = thy nx + thyInitialZeroes;
	long nx = mynx > thynx ? mynx : thynx;
	Sound him = Sound_create (2, xmin, xmax, nx, dx, x1); cherror
	for (long i = 1; i <= my nx; i ++) {
		his z [1] [i + myInitialZeroes] = my z [1] [i];
	}
	for (long i = 1; i <= thy nx; i ++) {
		his z [2] [i + thyInitialZeroes] = thy z [1] [i];
	}
end:
	iferror forget (him);
	return him;
}
Esempio n. 14
0
RealTier RealTier_create (double tmin, double tmax) {
	RealTier me = Thing_new (RealTier); cherror
	RealTier_init_e (me, tmin, tmax); cherror
end:
	iferror forget (me);
	return me;
}
Esempio n. 15
0
void Picture_copyToClipboard (Picture me) {
	/*
	 * Find the clipboard and clear it.
	 */
	PasteboardRef clipboard = nullptr;
	PasteboardCreate (kPasteboardClipboard, & clipboard);
	PasteboardClear (clipboard);
	/*
	 * Add a PDF flavour to the clipboard.
	 */
	static CGDataConsumerCallbacks callbacks = { appendBytes, nullptr };
	CFDataRef data = CFDataCreateMutable (kCFAllocatorDefault, 0);
	CGDataConsumerRef consumer = CGDataConsumerCreate ((void *) data, & callbacks);
	int resolution = 600;
	CGRect rect = CGRectMake (0, 0, (my selx2 - my selx1) * resolution, (my sely1 - my sely2) * resolution);
	CGContextRef context = CGPDFContextCreate (consumer, & rect, nullptr);
	//my selx1 * RES, (12 - my sely2) * RES, my selx2 * RES, (12 - my sely1) * RES)
	Graphics graphics = Graphics_create_pdf (context, resolution, my selx1, my selx2, my sely1, my sely2);
	Graphics_play ((Graphics) my graphics, graphics);
	forget (graphics);
	PasteboardPutItemFlavor (clipboard, (PasteboardItemID) 1, kUTTypePDF, data, kPasteboardFlavorNoFlags);
	CFRelease (data);
	/*
	 * Forget the clipboard.
	 */
	CFRelease (clipboard);
}
Esempio n. 16
0
FormantGrid FormantGrid_createEmpty (double tmin, double tmax, long numberOfFormants) {
	FormantGrid me = Thing_new (FormantGrid); cherror
	FormantGrid_init (me, tmin, tmax, numberOfFormants); cherror
end:
	iferror forget (me);
	return me;
}
Esempio n. 17
0
static void Collection_replaceItemPos (I, Any item, long pos) {
    iam (Collection);
    if (pos < 1 || pos > my size) {
        return;
    }
    forget ( ( (SimpleString *) my item) [pos]);
    my item[pos] = item;
}
Esempio n. 18
0
void structHyperPage :: v_destroy () {
	forget (links);
	Melder_free (entryHint);
	forget (g);
	for (int i = 0; i < 20; i ++) Melder_free (history [i]. page);
	Melder_free (currentPageTitle);
	if (praatApplication != NULL) {
		for (int iobject = ((PraatObjects) praatObjects) -> n; iobject >= 1; iobject --) {
			Melder_free (((PraatObjects) praatObjects) -> list [iobject]. name);
			forget (((PraatObjects) praatObjects) -> list [iobject]. object);
		}
		Melder_free (praatApplication);
		Melder_free (praatObjects);
		Melder_free (praatPicture);
	}
	HyperPage_Parent :: v_destroy ();
}
Esempio n. 19
0
class_methods_end

StringsIndex StringsIndex_create (long numberOfElements)
{
	StringsIndex me = Thing_new (StringsIndex);
	if (me == NULL || ! Index_init (me, numberOfElements)) forget (me);
	return me;
}
Esempio n. 20
0
FFNet FFNet_create (long numberOfInputs, long numberInLayer1, long numberInLayer2, 
	long numberOfOutputs, int outputsAreLinear)
{
    FFNet me = Thing_new (FFNet);
	if (me == NULL || ! FFNet_init (me, numberOfInputs, numberInLayer1, numberInLayer2, 
		numberOfOutputs, outputsAreLinear)) forget (me);
	return me;
}
Esempio n. 21
0
class_methods_end

Sound Sound_create (long numberOfChannels, double xmin, double xmax, long nx, double dx, double x1) {
	Sound me = Thing_new (Sound);
	if (! me || ! Matrix_init (me, xmin, xmax, nx, dx, x1, 1, numberOfChannels, numberOfChannels, 1, 1))
		forget (me);
	return me;
}
Esempio n. 22
0
/* =============================================================================
 * FUNCTION: act_on_object
 */
void take_item(int ans)
{
	if (ans != 't')
		return;

	if (take(item[playerx][playery], iarg[playerx][playery]) == 0)
		forget();
}
Esempio n. 23
0
void UiPause_begin (GuiWindow topShell, const wchar_t *title, Interpreter interpreter) {
	if (theEventLoopDepth > 0)
		Melder_throw ("Praat cannot have more than one pause form at a time.");
	forget (thePauseForm);   // in case an earlier build-up of another pause window was interrupted
	thePauseForm = UiForm_create (topShell, Melder_wcscat (L"Pause: ", title),
		thePauseFormOkCallback, interpreter,   // pass interpreter as closure!
		NULL, NULL);
}
Esempio n. 24
0
class_methods_end

Distance Distance_create (long numberOfPoints)
{
	Distance me = Thing_new (Distance);
	if (! me || ! Proximity_init (me, numberOfPoints)) forget (me);
	return me;
}
Esempio n. 25
0
void UiPause_option (const wchar_t *label) {
	if (thePauseForm == NULL)
		Melder_throw ("The function \"option\" has to be between a \"beginPause\" and an \"endPause\".");
	if (thePauseFormRadio == NULL) {
		forget (thePauseForm);
		Melder_throw ("Found the function \"option\" without a preceding \"choice\" or \"optionMenu\".");
	}
	UiOptionMenu_addButton (thePauseFormRadio, label);
}
Esempio n. 26
0
void EditDistanceTable_setEditCosts (EditDistanceTable me, EditCostsTable thee) {
    try {
        forget (my editCostsTable);
        autoEditCostsTable ect = (EditCostsTable) Data_copy (thee);
        my editCostsTable = ect.transfer();
    } catch (MelderError) {
        Melder_throw (me, U": edit costs not set.");
    }
}
Esempio n. 27
0
 cursor get_cursor() const {
   auto cur = collection_.get_cursor();
   auto n = n_;
   while (n-- && !cur.empty()) {
     cur.increase();
   }
   cur.forget();
   return std::move(cur);
 }
Esempio n. 28
0
int SoundEditor::menu_cb_Copy (EDITOR_ARGS) {
	SoundEditor *editor = (SoundEditor *)editor_me;
	Sound publish = editor->_longSound.data ? LongSound_extractPart ((LongSound) editor->_data, editor->_startSelection, editor->_endSelection, FALSE) :
		Sound_extractPart ((Sound) editor->_data, editor->_startSelection, editor->_endSelection, kSound_windowShape_RECTANGULAR, 1.0, FALSE);
	iferror return 0;
	forget (Sound_clipboard);
	Sound_clipboard = publish;
	return 1;
}
Esempio n. 29
0
Ltas PointProcess_Sound_to_Ltas (PointProcess pulses, Sound sound,
	double maximumFrequency, double bandWidth,
	double shortestPeriod, double longestPeriod, double maximumPeriodFactor)
{
	Ltas ltas = NULL, numbers = NULL;
	Sound period = NULL;
	Spectrum spectrum = NULL;
	long numberOfPeriods = pulses -> nt - 2, ipulse, ifreq, iband, totalNumberOfEnergies = 0;
	ltas = Ltas_create (maximumFrequency / bandWidth, bandWidth); cherror
	ltas -> xmax = maximumFrequency;
	numbers = (structLtas *)Data_copy (ltas);
	if (numberOfPeriods < 1) error1 (L"Cannot compute an Ltas if there are no periods in the point process.")
	for (ipulse = 2; ipulse < pulses -> nt; ipulse ++) {
		double leftInterval = pulses -> t [ipulse] - pulses -> t [ipulse - 1];
		double rightInterval = pulses -> t [ipulse + 1] - pulses -> t [ipulse];
		double intervalFactor = leftInterval > rightInterval ? leftInterval / rightInterval : rightInterval / leftInterval;
		Melder_progress4 ((double) ipulse / pulses -> nt, L"Sound & PointProcess: To Ltas: pulse ", Melder_integer (ipulse), L" out of ", Melder_integer (pulses -> nt));
		if (leftInterval >= shortestPeriod && leftInterval <= longestPeriod &&
		    rightInterval >= shortestPeriod && rightInterval <= longestPeriod &&
		    intervalFactor <= maximumPeriodFactor)
		{
			/*
			 * We have a period! Compute the spectrum.
			 */
			period = Sound_extractPart (sound,
				pulses -> t [ipulse] - 0.5 * leftInterval, pulses -> t [ipulse] + 0.5 * rightInterval,
				kSound_windowShape_RECTANGULAR, 1.0, FALSE); cherror
			spectrum = Sound_to_Spectrum (period, FALSE); cherror
			for (ifreq = 1; ifreq <= spectrum -> nx; ifreq ++) {
				double frequency = spectrum -> xmin + (ifreq - 1) * spectrum -> dx;
				double realPart = spectrum -> z [1] [ifreq];
				double imaginaryPart = spectrum -> z [2] [ifreq];
				double energy = (realPart * realPart + imaginaryPart * imaginaryPart) * 2.0 * spectrum -> dx /* OLD: * sound -> nx */;
				iband = ceil (frequency / bandWidth);
				if (iband >= 1 && iband <= ltas -> nx) {
					ltas -> z [1] [iband] += energy;
					numbers -> z [1] [iband] += 1;
					totalNumberOfEnergies += 1;
				}
			}
			forget (spectrum);
			forget (period);
		} else {
Esempio n. 30
0
	static void _guiGtkMenu_destroyCallback (GuiObject widget, gpointer void_me) {
		(void) void_me;
		GuiMenu me = (GuiMenu) _GuiObject_getUserData (widget);
		trace (U"destroying GuiMenu ", Melder_pointer (me));
		if (! me) return;   // we could be destroying me
		my d_widget = NULL;   // undangle
		if (my d_cascadeButton) my d_cascadeButton -> d_widget = NULL;   // undangle
		if (my d_menuItem) my d_menuItem -> d_widget = NULL;   // undangle
		forget (me);
	}