.gif stops after first frame (non playing gif)

edited June 2015 in Library Questions

Dear people,

I'm working on this code to start playing a .gif after I hit my electric drumkit (with midi). Can someone help me with why it won't play the full gif after I hit one of the drumpads?

Many thanks in advance!

Hidde

// SimpleMidi.pde
import gifAnimation.;
import themidibus.; //Import the library
import javax.sound.midi.MidiMessage;
Gif myAnimation;
MidiBus myBus;
//PShape yourSvgImage;
//PShape yourSvgImage1;
int currentColor = 255;
int midiDevice = 0;
HashMap<Integer, PImage> shapes;

void setup() {
    size(800, 800);
    smooth();

    myAnimation = new Gif(this, "gifcrash.gif");
    myAnimation.play();

    MidiBus.list();
    myBus = new MidiBus(this, midiDevice, 1);
    // yourSvgImage = loadShape("f.svg");
    // yourSvgImage1 = loadShape("f1.svg");
    shapes = new HashMap<Integer, PImage>();

    // shapes.put ( note nummer , de shape );
    shapes.put(43, new Gif(this, "gifcrash.gif"));
    shapes.put(25, loadImage("patterns/1.gif"));
}

void draw() {
    // background(currentColor);
}

void midiMessage(MidiMessage message, long timestamp, String bus_name) {
    int note = (int)(message.getMessage()[1] & 0xFF) ;
    int vel = (int)(message.getMessage()[2] & 0xFF);
    println("Bus " + bus_name + ": Note "+ note + ", vel " + vel);
    // if ( note == 25 ) { 
    //     shape(yourSvgImage, 280, 40); 
    //     Draw at coordinate (280, 40) at the default size 
    // } else if ( note == 50 ) { 
    //     shape(yourSvgImage1, 280, 40); 
    // }

    if (shapes.containsKey(note)) {
        PImage currentShape = shapes.get(note);
        image(currentShape, 0, 0);

        // fade uit 
        fill(150, 3); 
        noStroke(); 
        rect(0,0,width,height); 
    }

    // if (vel > 0 ) { 
    //     currentColor = vel*2; 
    // } 
}

Answers

  • Because it's not in draw(). midiMessage() only runs when a note is received, and only once (the image() method needs to be called for every frame in the gif). You'll need to find a way to transfer the image call to draw().

  • Answer ✓

    Moreover, don't modify sketch's canvas outside the "Animation" Thread! [-X

  • Thank you so much for your help, clouredmirrorball & GoToLoop!

Sign In or Register to comment.