void Spectrum_getNearestMaximum (Spectrum me, double frequency, double *frequencyOfMaximum, double *heightOfMaximum) { try { autoSpectrumTier thee = Spectrum_to_SpectrumTier_peaks (me); long index = AnyTier_timeToNearestIndex (thee.peek(), frequency); if (index == 0) Melder_throw ("No peak."); RealPoint point = (RealPoint) thy points -> item [index]; *frequencyOfMaximum = point -> number; *heightOfMaximum = point -> value; } catch (MelderError) { Melder_throw (me, ": no nearest maximum found."); } }
bool structFormantGridEditor :: v_click (double xWC, double yWC, bool shiftKeyPressed) { FormantGrid grid = (FormantGrid) our data; Ordered tiers = editingBandwidths ? grid -> bandwidths : grid -> formants; RealTier tier = (RealTier) tiers -> item [selectedFormant]; double ymin = our editingBandwidths ? our p_bandwidthFloor : our p_formantFloor; double ymax = our editingBandwidths ? our p_bandwidthCeiling : our p_formantCeiling; long inearestPoint, ifirstSelected, ilastSelected; RealPoint nearestPoint; double dt = 0, df = 0; bool draggingSelection; /* * Perform the default action: move cursor. */ //d_startSelection = d_endSelection = xWC; our ycursor = (1.0 - yWC) * ymin + yWC * ymax; Graphics_setWindow (our d_graphics, our d_startWindow, our d_endWindow, ymin, ymax); yWC = our ycursor; /* * Clicked on a point? */ inearestPoint = AnyTier_timeToNearestIndex (tier, xWC); if (inearestPoint == 0) { return FormantGridEditor_Parent :: v_click (xWC, yWC, shiftKeyPressed); } nearestPoint = (RealPoint) tier -> points -> item [inearestPoint]; if (Graphics_distanceWCtoMM (our d_graphics, xWC, yWC, nearestPoint -> number, nearestPoint -> value) > 1.5) { return our FormantGridEditor_Parent :: v_click (xWC, yWC, shiftKeyPressed); } /* * Clicked on a selected point? */ draggingSelection = shiftKeyPressed && nearestPoint -> number > our d_startSelection && nearestPoint -> number < our d_endSelection; if (draggingSelection) { ifirstSelected = AnyTier_timeToHighIndex (tier, our d_startSelection); ilastSelected = AnyTier_timeToLowIndex (tier, our d_endSelection); Editor_save (this, U"Drag points"); } else { ifirstSelected = ilastSelected = inearestPoint; Editor_save (this, U"Drag point"); } /* * Drag. */ Graphics_xorOn (our d_graphics, Graphics_MAROON); drawWhileDragging (this, xWC, yWC, ifirstSelected, ilastSelected, dt, df); while (Graphics_mouseStillDown (our d_graphics)) { double xWC_new, yWC_new; Graphics_getMouseLocation (our d_graphics, & xWC_new, & yWC_new); if (xWC_new != xWC || yWC_new != yWC) { drawWhileDragging (this, xWC, yWC, ifirstSelected, ilastSelected, dt, df); dt += xWC_new - xWC, df += yWC_new - yWC; xWC = xWC_new, yWC = yWC_new; drawWhileDragging (this, xWC, yWC, ifirstSelected, ilastSelected, dt, df); } } Graphics_xorOff (our d_graphics); /* * Dragged inside window? */ if (xWC < d_startWindow || xWC > d_endWindow) return 1; /* * Points not dragged past neighbours? */ RealPoint *points = (RealPoint *) tier -> points -> item; double newTime = points [ifirstSelected] -> number + dt; if (newTime < our tmin) return 1; // outside domain if (ifirstSelected > 1 && newTime <= points [ifirstSelected - 1] -> number) return 1; // past left neighbour newTime = points [ilastSelected] -> number + dt; if (newTime > our tmax) return 1; // outside domain if (ilastSelected < tier -> points -> size && newTime >= points [ilastSelected + 1] -> number) return FunctionEditor_UPDATE_NEEDED; // past right neighbour /* * Drop. */ for (long i = ifirstSelected; i <= ilastSelected; i ++) { RealPoint point = (RealPoint) tier -> points -> item [i]; point -> number += dt; point -> value += df; } /* * Make sure that the same points are still selected (a problem with Undo...). */ if (draggingSelection) our d_startSelection += dt, our d_endSelection += dt; if (ifirstSelected == ilastSelected) { /* * Move crosshair to only selected formant point. */ RealPoint point = (RealPoint) tier -> points -> item [ifirstSelected]; our d_startSelection = our d_endSelection = point -> number; our ycursor = point -> value; } else { /* * Move crosshair to mouse location. */ /*our cursor += dt;*/ our ycursor += df; } Editor_broadcastDataChanged (this); return FunctionEditor_UPDATE_NEEDED; }
void AnyTier_removePointNear (AnyTier me, double time) { long ipoint = AnyTier_timeToNearestIndex (me, time); if (ipoint) my points.removeItem (ipoint); }
void AnyTier_removePointNear (I, double time) { iam (AnyTier); long ipoint = AnyTier_timeToNearestIndex (me, time); if (ipoint) Collection_removeItem (my points, ipoint); }
FORM (INTEGER_TimeTier_getHighIndexFromTime, U"Get high index", U"AnyTier: Get high index from time...") { REALVAR (time, U"Time (s)", U"0.5") OK DO FIND_ONE (AnyTier) Melder_information (my points.size == 0 ? U"--undefined--" : Melder_integer (AnyTier_timeToHighIndex (me, GET_REAL (U"Time")))); END } FORM (INTEGER_TimeTier_getNearestIndexFromTime, U"Get nearest index", U"AnyTier: Get nearest index from time...") { REALVAR (time, U"Time (s)", U"0.5") OK DO FIND_ONE (AnyTier) Melder_information (my points.size == 0 ? U"--undefined--" : Melder_integer (AnyTier_timeToNearestIndex (me, GET_REAL (U"Time")))); END } FORM (REAL_TimeTier_getTimeFromIndex, U"Get time", nullptr /*"AnyTier: Get time from index..."*/) { NATURALVAR (pointNumber, U"Point number", U"10") OK DO FIND_ONE (AnyTier) if (pointNumber > my points.size) Melder_information (U"--undefined--"); else Melder_informationReal (my points.at [pointNumber] -> number, U"seconds"); END } // MARK: Modify