Ejemplo n.º 1
0
void wfx_smooth(Wave *w, int a, int b) {

	int d = 32;  // 64 if stereo data

	/* do nothing if fade edges (both of 32 samples) are > than selected
	 * portion of wave. d*2 => count both edges, (b-a)*2 => stereo
	 * values. */

	if (d*2 > (b-a)*2) {
		gLog("[WFX] selection is too small, nothing to do\n");
		return;
	}

	wfx_fade(w, a, a+d, 0);
	wfx_fade(w, b-d, b, 1);
}
Ejemplo n.º 2
0
void gWaveform::openEditMenu() {

	if (selectionA == selectionB)
		return;

	menuOpen = true;

	Fl_Menu_Item menu[] = {
		{"Cut"},
		{"Trim"},
		{"Silence"},
		{"Fade in"},
		{"Fade out"},
		{"Smooth edges"},
		{"Set start/end here"},
		{0}
	};

	if (chan->status == STATUS_PLAY) {
		menu[0].deactivate();
		menu[1].deactivate();
	}

	Fl_Menu_Button *b = new Fl_Menu_Button(0, 0, 100, 50);
	b->box(G_BOX);
	b->textsize(11);
	b->textcolor(COLOR_TEXT_0);
	b->color(COLOR_BG_0);

	const Fl_Menu_Item *m = menu->popup(Fl::event_x(), Fl::event_y(), 0, 0, b);
	if (!m) {
		menuOpen = false;
		return;
	}

	/* straightSel() to ensure that point A is always lower than B */

	straightSel();

	if (strcmp(m->label(), "Silence") == 0) {
		wfx_silence(chan->wave, absolutePoint(selectionA), absolutePoint(selectionB));

		selectionA = 0;
		selectionB = 0;

		stretchToWindow();
		redraw();
		menuOpen = false;
		return;
	}

	if (strcmp(m->label(), "Set start/end here") == 0) {

		glue_setBeginEndChannel(
				(gdEditor *) window(), // parent
				chan,
				absolutePoint(selectionA) * 2,  // stereo!
				absolutePoint(selectionB) * 2,  // stereo!
				false, // no recalc (we do it here)
				false  // don't check
				);

		selectionA     = 0;
		selectionB     = 0;
		selectionA_abs = 0;
		selectionB_abs = 0;

		recalcPoints();
		redraw();
		menuOpen = false;
		return;
	}

	if (strcmp(m->label(), "Cut") == 0) {
		wfx_cut(chan->wave, absolutePoint(selectionA), absolutePoint(selectionB));

		/* for convenience reset start/end points */

		glue_setBeginEndChannel(
			(gdEditor *) window(),
			chan,
			0,
			chan->wave->size,
			false);

		selectionA     = 0;
		selectionB     = 0;
		selectionA_abs = 0;
		selectionB_abs = 0;

		setZoom(0);

		menuOpen = false;
		return;
	}

	if (strcmp(m->label(), "Trim") == 0) {
		wfx_trim(chan->wave, absolutePoint(selectionA), absolutePoint(selectionB));

		glue_setBeginEndChannel(
			(gdEditor *) window(),
			chan,
			0,
			chan->wave->size,
			false);

		selectionA     = 0;
		selectionB     = 0;
		selectionA_abs = 0;
		selectionB_abs = 0;

		stretchToWindow();
		menuOpen = false;
		redraw();
		return;
	}

	if (!strcmp(m->label(), "Fade in") || !strcmp(m->label(), "Fade out")) {

		int type = !strcmp(m->label(), "Fade in") ? 0 : 1;
		wfx_fade(chan->wave, absolutePoint(selectionA), absolutePoint(selectionB), type);

		selectionA = 0;
		selectionB = 0;

		stretchToWindow();
		redraw();
		menuOpen = false;
		return;
	}

	if (!strcmp(m->label(), "Smooth edges")) {

		wfx_smooth(chan->wave, absolutePoint(selectionA), absolutePoint(selectionB));

		selectionA = 0;
		selectionB = 0;

		stretchToWindow();
		redraw();
		menuOpen = false;
		return;
	}
}