M21Code / ProcessingVideo / ProcessingVideo.pde
ProcessingVideo.pde
Raw
//Needed to set up a serial connection with Arduino
import processing.serial.*;
Serial myPort;

//Libraries, for setting fonts
import java.applet.Applet;  
import java.awt.Font;  
import java.awt.Graphics;

//library + variables for the Dropdownlists
import g4p_controls.*;
GLabel lblpNumSelecter;
GDropList pNumDropdownList;
GLabel lblArousalSelecter;
GDropList arousalDropdownList;
GLabel lblValenceSelecter;
GDropList valenceDropdownList;
GLabel lblFamiliaritySelecter;
GDropList familiarityDropdownList;
GLabel lblComfortSelecter;
GDropList comfortDropdownList;

//Libraries, for video + audio capabilities
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
import processing.video.*;
import processing.sound.*;
import javax.sound.sampled.*;

//Minim, for outputting the audio to the vibrotactile device
Minim minim;
MultiChannelBuffer sampleBuffer;
AudioOutput output;
Sampler sampler;
Mixer.Info[] mixerInfo;

//AudioPlayers, contain the audio files to send to the vibrotactile device
AudioPlayer[] playlistSound;
AudioPlayer[] playlistHighFreq;
AudioPlayer[] playlistLowFreq;

//Video, for loading the different videos
int NOMOVIE = -100;
int n = 12;
Movie mov[];
int chosenVideo = NOMOVIE; //To start without error
int shownVideo; //last movie shown (purely for table purpose)
long startMillis;
long currentMillis;
float duration;
long lastUpdate = millis();

//Lists for the order of the videos and modes for each participant
IntList Inventories[];
IntList Orders[];
IntList Temps[];
int p = 12;

//For the logging of answers of questions
Table table;
Table table2;
int pNum;
int vibroMode;
int arousalVal = 0;
int valenceVal = 0;
String familiarityVal;
int comfortVal = 0;
int temp;
String serialReceived;

//Button for next video
PImage playButton;

void setup() {
  size(1280, 960);
  surface.setLocation(300, 10);
  background (0);

  printArray(Serial.list()); //Show to check if the right Serial port will be selected
  String portName = Serial.list()[3]; //Choose the number that the ESP32 is connected to on Arduino, preferebly COM7
  myPort = new Serial(this, portName, 115200);

  G4P.setCursor(CROSS);
  makepNumSelecter();

  //Setting up the audio output to the vibration device
  minim = new Minim(this);
  mixerInfo = AudioSystem.getMixerInfo();
  for (int i = 0; i < mixerInfo.length; i++)
  {    
    println(i + " = " + mixerInfo[i].getName());
  } 
  Mixer mixer = AudioSystem.getMixer(mixerInfo[2]); //choose the number that says 'M5_Speaker_T1 Stereo'
  minim.setOutputMixer(mixer);
  output = minim.getLineOut();
  sampleBuffer = new MultiChannelBuffer( 32, 1 );

  files(); //loads all the mp4 and mp3 files for playing
  lists(); //loads the participant-specific lists of video/vibrotactile orders
  table(); //creates a table in a seperate csv file

  playButton = loadImage("playButton.png");
}

void draw() {
  currentMillis = millis();

  while (myPort.available() > 0) {
    serialReceived = myPort.readString();   
    //if (serialReceived != null) {
    //  println(serialReceived);
    //}
  }

  if (millis() > lastUpdate + 500) {
    saveTemps();
    lastUpdate = millis();
  }

  if (chosenVideo != NOMOVIE) {
    imageMode(CENTER);
    image(mov[chosenVideo], width/2, height/2, mov[chosenVideo].width*2, mov[chosenVideo].height*2);
    playOne(chosenVideo);

    if (currentMillis - startMillis >= duration) {
      stopOne(chosenVideo);
    }
  } else {
    imageMode(CENTER);
    nextVideo();
  }
}