Esempio n. 1
0
void export_wav(MusSong *song, CydWavetableEntry * entry, FILE *f, int channel)
{
	MusEngine mus;
	CydEngine cyd;
	
	cyd_init(&cyd, 44100, MUS_MAX_CHANNELS);
	cyd.flags |= CYD_SINGLE_THREAD;
	mus_init_engine(&mus, &cyd);
	mus.volume = song->master_volume;
	mus_set_fx(&mus, song);
	CydWavetableEntry * prev_entry = cyd.wavetable_entries; // save entries so they can be free'd
	cyd.wavetable_entries = entry;
	cyd_set_callback(&cyd, mus_advance_tick, &mus, song->song_rate);
	mus_set_song(&mus, song, 0);
	song->flags |= MUS_NO_REPEAT;
	
	if (channel >= 0)
	{
		// if channel is positive then only export that channel (mute other chans)
		
		for (int i = 0 ; i < MUS_MAX_CHANNELS ; ++i)
			mus.channel[i].flags |= MUS_CHN_DISABLED;
		
		mus.channel[channel].flags &= ~MUS_CHN_DISABLED;
	}
	else
	{
		for (int i = 0 ; i < MUS_MAX_CHANNELS ; ++i)
			mus.channel[i].flags &= ~MUS_CHN_DISABLED;
	}
	
	const int channels = 2;
	Sint16 buffer[2000 * channels];
	
	int last_percentage = -1;
	
	WaveWriter *ww = ww_create(f, cyd.sample_rate, 2);
	
	for (;;)
	{
		memset(buffer, 0, sizeof(buffer)); // Zero the input to cyd
		cyd_output_buffer_stereo(&cyd, (Uint8*)buffer, sizeof(buffer));
		
		if (cyd.samples_output > 0)
			ww_write(ww, buffer, cyd.samples_output);
		
		if (mus.song_position >= song->song_length) break;
		
		if (song->song_length != 0)
		{
			int percentage = (mus.song_position + (channel == -1 ? 0 : (channel * song->song_length))) * 100 / (song->song_length * (channel == -1 ? 1 : song->num_channels));
			
			if (percentage > last_percentage)
			{
				last_percentage = percentage;
				
				SDL_Rect area = {domain->screen_w / 2 - 140, domain->screen_h / 2 - 24, 280, 48};
				bevel(domain, &area, mused.slider_bevel, BEV_MENU);
				
				adjust_rect(&area, 8);
				area.h = 16;
				
				bevel(domain, &area, mused.slider_bevel, BEV_FIELD);
				
				adjust_rect(&area, 2);
				
				int t = area.w;
				area.w = area.w * percentage / 100;
				
				gfx_rect(domain, &area, colors[COLOR_PROGRESS_BAR]);
				
				area.y += 16 + 4 + 4;
				area.w = t;
				
				font_write_args(&mused.smallfont, domain, &area, "Exporting... Press ESC to abort.");
				
				SDL_Event e;
				
				while (SDL_PollEvent(&e))
				{
					if (e.type == SDL_QUIT || (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE))
					{
						goto abort;
					}
				}
				
				gfx_domain_flip(domain);
			}
		}
	}
	
abort:;
	
	ww_finish(ww);
	
	cyd.wavetable_entries = prev_entry;
	
	cyd_deinit(&cyd);
	
	song->flags &= ~MUS_NO_REPEAT;
}
Esempio n. 2
0
void BorderFilter::filterImage()
{
    d->setup(m_orgImage);

    switch (d->settings.borderType)
    {
        case BorderContainer::SolidBorder:

            if (d->settings.preserveAspectRatio)
            {
                solid(m_orgImage, m_destImage, d->solidColor, d->borderMainWidth);
            }
            else
            {
                solid2(m_orgImage, m_destImage, d->solidColor, d->settings.borderWidth1);
            }

            break;

        case BorderContainer::NiepceBorder:

            if (d->settings.preserveAspectRatio)
                niepce(m_orgImage, m_destImage, d->niepceBorderColor, d->borderMainWidth,
                       d->niepceLineColor, d->border2ndWidth);
            else
                niepce2(m_orgImage, m_destImage, d->niepceBorderColor, d->settings.borderWidth1,
                        d->niepceLineColor, d->settings.borderWidth4);

            break;

        case BorderContainer::BeveledBorder:

            if (d->settings.preserveAspectRatio)
                bevel(m_orgImage, m_destImage, d->bevelUpperLeftColor,
                      d->bevelLowerRightColor, d->borderMainWidth);
            else
                bevel2(m_orgImage, m_destImage, d->bevelUpperLeftColor,
                       d->bevelLowerRightColor, d->settings.borderWidth1);

            break;

        case BorderContainer::PineBorder:
        case BorderContainer::WoodBorder:
        case BorderContainer::PaperBorder:
        case BorderContainer::ParqueBorder:
        case BorderContainer::IceBorder:
        case BorderContainer::LeafBorder:
        case BorderContainer::MarbleBorder:
        case BorderContainer::RainBorder:
        case BorderContainer::CratersBorder:
        case BorderContainer::DriedBorder:
        case BorderContainer::PinkBorder:
        case BorderContainer::StoneBorder:
        case BorderContainer::ChalkBorder:
        case BorderContainer::GraniteBorder:
        case BorderContainer::RockBorder:
        case BorderContainer::WallBorder:

            if (d->settings.preserveAspectRatio)
                pattern(m_orgImage, m_destImage, d->borderMainWidth,
                        d->decorativeFirstColor, d->decorativeSecondColor,
                        d->border2ndWidth, d->border2ndWidth);
            else
                pattern2(m_orgImage, m_destImage, d->settings.borderWidth1,
                         d->decorativeFirstColor, d->decorativeSecondColor,
                         d->settings.borderWidth2, d->settings.borderWidth2);

            break;
    }
}