Exemple #1
0
/** FLA movie process frame */
void processFrame() {
	FLASampleStruct sample;
	uint32 opcodeBlockSize;
	uint8 opcode;
	int32 aux = 0;
	uint8 * ptr;

	frread(&frFla, &frameData.videoSize, 1);
	frread(&frFla, &frameData.dummy, 1);
	frread(&frFla, &frameData.frameVar0, 4);

	frread(&frFla, workVideoBufferCopy, frameData.frameVar0);

	if ((int32)frameData.videoSize <= 0)
		return;

	ptr = workVideoBufferCopy;

	do {
		opcode = *((uint8*)ptr);
		ptr += 2;
		opcodeBlockSize = *((uint16*)ptr);
		ptr += 2;

		switch (opcode - 1) {
		case kLoadPalette: {
			int16 numOfColor = *((int16*)ptr);
			int16 startColor = *((int16*)(ptr + 2));
			memcpy((palette + (startColor*3)), (ptr + 4), numOfColor*3);
			break;
		}
		case kFade: {
			// FLA movies don't use cross fade
			// fade out tricky
			if (_fadeOut != 1) {
				convertPalToRGBA(palette, paletteRGBACustom);
				fadeToBlack(paletteRGBACustom);
				_fadeOut = 1;
			}
			break;
		}
		case kPlaySample: {
			memcpy(&sample, ptr, sizeof(FLASampleStruct));
			playFlaSample(sample.sampleNum, sample.freq, sample.repeat, sample.x, sample.y);
			break;
		}
		case kStopSample: {
			stopSample(sample.sampleNum);
			break;
		}
		case kDeltaFrame: {
			drawDeltaFrame(ptr, FLASCREEN_WIDTH);
			if (_fadeOut == 1)
				fadeOutFrames++;
			break;
		}
		case kKeyFrame: {
			drawKeyFrame(ptr, FLASCREEN_WIDTH, FLASCREEN_HEIGHT);
			break;
		}
		default: {
			return;
		}
		}

		aux++;
		ptr += opcodeBlockSize;

	} while (aux < (int32)frameData.videoSize);
	//free(workVideoBufferCopy);
}
bool SamplerWidget::on_button_press_event(GdkEventButton* event)
{
	//std::cout << "Press  Event Type: " << event->type << ". Event Button: " << event->button << "." << std::endl;
	
	if( event->type == GDK_BUTTON_PRESS && event->button == 1 ) // left click=play
	{
		//lo_send(addr, "/luppp/sampler/play","i", samplerNumber); // play
		padOn();
		redraw();
		return true;
	}
	if( event->type == GDK_BUTTON_PRESS && event->button == 2 ) // change me
	{
		std::string loadThisSample;
		
		
		// Hack fix: fileChooser wasnt linking: creating one here instead.
		Gtk::FileChooserDialog dialog( "Choose a Sample to load" , Gtk::FILE_CHOOSER_ACTION_OPEN);
		dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
		dialog.add_button("Select", Gtk::RESPONSE_OK);
		
		int result = dialog.run();
		
		switch (result)
		{
			case Gtk::RESPONSE_OK:
			{
				//std::cout << "FileChooser: Response Accept" << std::endl;
				loadThisSample = dialog.get_filename();
				break;
			}
			default:
			{
				//std::cout << "FileChooser: Response Cancel" << std::endl;
				loadThisSample = "";
				break;
			}
		}
		// end hack fix
		
		// Original code
		//FileChooser fileChooser
		//loadThisSample = fileChooser.show("Choose a Sample to load!",Gtk::FILE_CHOOSER_ACTION_OPEN);
		
		
		
		// Send OSC load command
		if (loadThisSample != "")
		{
			//lo_send(addr, "/luppp/sampler/load","is", samplerNumber,loadThisSample.c_str());
			
			// Now cut the path & filename to filename, and set the samples "name"
			loadThisSample = loadThisSample.substr(loadThisSample.rfind("/")+1);
			std::size_t pos = loadThisSample.rfind(".");
			
			// For checking string lenghts
			std::cout << "POS: " << pos << std::endl;
			
			if (loadThisSample.size() < 10)
				setSampleName( loadThisSample.substr( 0,  loadThisSample.size() - pos  ) );
			else
				setSampleName( loadThisSample.substr( 0,  9 ) ); // max lenght 9 chars
		}
		redraw();
		return true;
		
	}
	else if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) //  Change mode
	{
		if( !loopSampleBool )
		{
			//lo_send(addr, "/luppp/sampler/play","iii", samplerNumber,-1,0); // loop inf
			loopSample();
		}
		else
		{
			stopSample();
			//lo_send(addr, "/luppp/sampler/stop","i", samplerNumber); //stop
		}
		redraw();
		return true;
	}
	redraw();
}