123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
-
- Movie movie;
- boolean moviePlaying, imageChanged;
- PImage fallbackImage;
-
- void movieEvent(Movie m) {
- if (moviePlaying) {
- m.read();
- //if mode = 1..
- sourceManager.setImage(movie.get());
- //movie.jump(random(movie.duration())); //??
- }
- }
- void newMovie(String path) {
- movie = new Movie(this, path);
- }
-
- boolean isVideo(String path) {
- String fpl = path.toLowerCase();
- if (fpl.endsWith(".mp4") || fpl.endsWith(".avi") || fpl.endsWith(".webm") || fpl.endsWith(".mkv") || fpl.endsWith(".mov")) return true;
- else return false;
- }
- boolean isImage(String path) {
- String fpl = path.toLowerCase();
- if (fpl.endsWith(".bmp") || fpl.endsWith(".png") || fpl.endsWith(".jpg") || fpl.endsWith(".jpeg") || fpl.endsWith(".gif")) return true; //gif = special case!
- else return false;
- }
-
- class SourceManager { //no constructor
-
-
- void setSource() { //set source to renderer
- renderer.beginDraw();
- renderer.image(source, 0, 0, renderer.width, renderer.height);
- renderer.endDraw();
- }
-
- void setImage(PImage img) { //set image to source
- imageChanged = true;
- source = img.get();
- //if(!webcamMode) fallbackImage = source;
- fallbackImage = source;
- nativeResoX = source.width;
- nativeResoY = source.height;
- //println(nativeResoX);
- }
-
- void fallback() {
- println("Fallback");
- setImage(fallbackImage); //fallbackImage should always be a copy of the last image that worked
- }
- /*
- void startWebcam() {
- String[] cameras = Capture.list();
- println(cameras);
- cam.start();
- webcamMode = true;
- }
- void stopWebcam() {
- cam.stop();
- webcamMode = false;
- }*/
-
- void update() {
- /*
- if (webcamMode) {
- if (cam.available()) {
- cam.read();
- setImage(cam);
- }
- }
- */
-
- if (source == null) {
- fallback();
- }
-
- int toW, toH;
- if (source.width > source.height) {
- toW = renderSize;
- toH = int(map(source.height, 0, source.width, 0, renderSize));
- } else {
- toW = int(map(source.width, 0, source.height, 0, renderSize));
- toH = renderSize;
- }
- toW = (toW % 2 == 0) ? toW : toW+1;
- toH = (toH % 2 == 0) ? toH : toH+1;
-
- renderer.setSize(toW, toH);
- }
-
-
- // This function returns all the files in a directory as an array of Strings
- String[] listFileNames(String dir) {
- File file = new File(dir);
- if (file.isDirectory()) {
- String names[] = file.list();
- return names;
- } else {
- return null;
- }
- }
-
-
- String dir;
- String[] selection;
- int selId;
- void importURI(String path) {
- File file = new File(path);
- if (file.isDirectory()) {
- dir = path;
- String names[] = file.list();
- ArrayList<String> usableFiles = new ArrayList<String>();
- for (int i = 0; i < names.length; i++) {
- if (isImage(names[i]) || isVideo(names[i])) {
- usableFiles.add(names[i]);
- }
- }
- selection = new String[usableFiles.size()];
- for (int i = 0; i < usableFiles.size(); i++) selection[i] = usableFiles.get(i);
- println("Got new selection from folder. " + selection.length + " usable files.");
- path = dir + "/" + selection[(int)random(selection.length)];
- }
-
-
- if (isImage(path) || isVideo(path)) {
- println("Importing file " + path);
- if (moviePlaying) movie.stop();
- //if (webcamMode) gui.webcam.setValue(false);
- if (isImage(path)) {
- moviePlaying = false;
- setImage(loadImage(path));
- } else if (isVideo(path)) {
- moviePlaying = true;
- newMovie(path);
- movie.loop();
- movie.volume(0);
- }
- }
- }
- }
|