/*
	This file is part of "Interface Fractures IV - Q".
	Copyright (c) 2016 Luka Prinčič, All rights reserved.
	This program is free software distributed under
	GNU General Public Licence. See COPYING for more info.
	- - - - - - - - - - - - - - - - - - - - - - - - - - - -
  oscEvent.pde - processes incoming osc messages
                                                                             */

void oscEvent(OscMessage theOscMessage) {

  if(theOscMessage.checkTypetag("si")) {
    oscVal1 = theOscMessage.get(0).stringValue();
    oscVal2 = float(theOscMessage.get(1).intValue());
  }
  if(theOscMessage.checkTypetag("sf")) {
    oscVal1 = theOscMessage.get(0).stringValue();
    oscVal2 = theOscMessage.get(1).floatValue();
  }
  if(theOscMessage.checkTypetag("ii")) {
    oscVal1 = str(theOscMessage.get(0).intValue());
    oscVal2 = theOscMessage.get(1).intValue();
  }


  /*
  // direct translation?
  // SuperCollider direct osc paths
  if(theOscMessage.checkAddrPattern("/var")==true) {
    //(oscVal1[]) = oscVal2;
  }

  
  // SuperCollider direct osc paths
  if(theOscMessage.checkAddrPattern("/highhat")==true) {

    if(oscVal1.equals( "amp")) { ampColor = oscVal2; println("amp:"+oscVal2); }

  }
  */

  
  // OSC patchbay

  // /ctlin - Renoise-midi > SuperCollider-OSC
  if(theOscMessage.checkAddrPattern("/ctlin")==true) {


    // screenClean
    if(oscVal1.equals( "/screenCleanHue" )) {  screenCleanHue = oscVal2 ; }
    if(oscVal1.equals( "/screenCleanSaturation" )) {  screenCleanSaturation = oscVal2 ; }
    if(oscVal1.equals( "/screenCleanBrightness" )) {  screenCleanBrightness = oscVal2 ; }
    if(oscVal1.equals( "/screenCleanAlpha" )) {  screenCleanAlpha = oscVal2 ; }
    if(oscVal1.equals( "/screenCleanFlickrAmount" )) {  screenCleanFlickrAmount = oscVal2 ; }
    if(oscVal1.equals( "/screenCleanFlickrSpeed" )) {  screenCleanFlickrSpeed = oscVal2 ; }
    

    // drawFlylines
    if(oscVal1.equals( "/drawFlylinesflyToggle" )) {  drawFlylinesflyToggle  = boolean(int(oscVal2)) ;  }
    if(oscVal1.equals( "/drawFlylinesflyCurvesNum" )) {  drawFlylinesflyCurvesNum  = int(map(oscVal2, 0, 127, 0, 7000)); }
    if(oscVal1.equals( "/drawFlylinesflyPixBank" )) {  drawFlylinesflyPixBank = int(oscVal2) ; }
    if(oscVal1.equals( "/drawFlylinesflyPixId" )) {  drawFlylinesflyPixId = int(oscVal2) ; }
    if(oscVal1.equals( "/drawFlylinesflySpeed" )) {  drawFlylinesflySpeed = oscVal2 ; }
    if(oscVal1.equals( "/drawFlylinesflyDirection" )) {  drawFlylinesflyDirection = oscVal2 ; }
    if(oscVal1.equals( "/drawFlylinesSensitivity" )) {  drawFlylinesSensitivity = map(oscVal2, 0, 127, 0, 1) ; }
    if(oscVal1.equals( "/drawFlylinesflyBrightDirection" )) {  drawFlylinesflyBrightDirection  = oscVal2 ; }
    if(oscVal1.equals( "/drawFlylinesflyRotation" )) {  drawFlylinesflyRotation = oscVal2 ; }
    if(oscVal1.equals( "/drawFlylinesflyBrightRotation" )) {  drawFlylinesflyBrightRotation = oscVal2 ; }
    if(oscVal1.equals( "/drawFlylinesHue" )) {  drawFlylinesHue = int(oscVal2) ; }
    if(oscVal1.equals( "/drawFlylinesSatur" )) {  drawFlylinesSatur = int(oscVal2) ; }
    if(oscVal1.equals( "/drawFlylinesBright" )) {  drawFlylinesBright  = int(oscVal2) ; }
    if(oscVal1.equals( "/drawFlylinesAlpha" )) {  drawFlylinesAlpha = int(oscVal2) ; }
    if(oscVal1.equals( "/drawFlylinesBrightAlpha" )) {  drawFlylinesBrightAlpha = oscVal2 ; }
    if(oscVal1.equals( "/drawFlylinesLineLength" )) {  drawFlylinesLineLength = int(oscVal2) ; }
    if(oscVal1.equals( "/drawFlylinesBrightLength" )) {  drawFlylinesBrightLength = map(oscVal2, 0, 127, 0, 1) ; }
    if(oscVal1.equals( "/drawFlylinesStrokeWeight" )) {  drawFlylinesStrokeWeight = int(oscVal2) ; }
    if(oscVal1.equals( "/drawFlylinesPixHue" )) {  drawFlylinesPixHue = int(oscVal2) ; }
    if(oscVal1.equals( "/drawFlylinesPixSatur" )) {  drawFlylinesPixSatur = int(oscVal2) ; }
    if(oscVal1.equals( "/drawFlylinesPixBright" )) {  drawFlylinesPixBright = int(oscVal2) ; }
    if(oscVal1.equals( "/drawFlylinesPixAlpha" )) {  drawFlylinesPixAlpha = int(oscVal2) ; }



    // drawPlates
    if(oscVal1.equals( "/drawPlatesToggle" )) {  drawPlatesToggle = boolean(int(oscVal2)) ; }

    if(oscVal1.equals( "/drawPlatesimgAbank" )) {  drawPlatesimgAbank = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgAid" )) {  drawPlatesimgAid = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesTexAspeed" )) {  drawPlatesTexAspeed = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesTexAdirection" )) {  drawPlatesTexAdirection = int(oscVal2) ; }

    if(oscVal1.equals( "/drawPlatesimgATopLeft" )) {  drawPlatesimgATopLeft = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgATopRight" )) {  drawPlatesimgATopRight = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgABotRight" )) {  drawPlatesimgABotRight = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgABotleft" )) {  drawPlatesimgABotleft = int(oscVal2) ; }

    if(oscVal1.equals( "/drawPlatesimgAalpha" )) {  drawPlatesimgAalpha = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgAhue" )) {  drawPlatesimgAhue = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgAbright" )) {  drawPlatesimgAbright = int(oscVal2) ; }

    if(oscVal1.equals( "/drawPlatesimgBbank" )) {  drawPlatesimgBbank = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgBid" )) {  drawPlatesimgBid = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesTexBspeed" )) {  drawPlatesTexBspeed = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesTexBdirection" )) {  drawPlatesTexBdirection = int(oscVal2) ; }

    if(oscVal1.equals( "/drawPlatesimgBTopLeft" )) {  drawPlatesimgBTopLeft = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgBTopRight" )) {  drawPlatesimgBTopRight = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgBBotRight" )) {  drawPlatesimgBBotRight = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgBBotleft" )) {  drawPlatesimgBBotleft = int(oscVal2) ; }

    if(oscVal1.equals( "/drawPlatesimgBalpha" )) {  drawPlatesimgBalpha = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgBhue" )) {  drawPlatesimgBhue = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgBbright" )) {  drawPlatesimgBbright = int(oscVal2) ; }

    if(oscVal1.equals( "/drawPlatesimgCbank" )) {  drawPlatesimgCbank = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgCid" )) {  drawPlatesimgCid = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesTexCspeed" )) {  drawPlatesTexCspeed = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesTexCdirection" )) {  drawPlatesTexCdirection = int(oscVal2) ; }

    if(oscVal1.equals( "/drawPlatesimgCTopLeft" )) {  drawPlatesimgCTopLeft = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgCTopRight" )) {  drawPlatesimgCTopRight = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgCBotRight" )) {  drawPlatesimgCBotRight = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgCBotleft" )) {  drawPlatesimgCBotleft = int(oscVal2) ; }

    if(oscVal1.equals( "/drawPlatesimgCalpha" )) {  drawPlatesimgCalpha = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgChue" )) {  drawPlatesimgChue = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgCbright" )) {  drawPlatesimgCbright = int(oscVal2) ; }

    if(oscVal1.equals( "/drawPlatesimgBblendMode" )) {  drawPlatesimgBblendMode = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesimgCblendMode" )) {  drawPlatesimgCblendMode = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesSaturation" )) {  drawPlatesSaturation = int(oscVal2) ; }
    if(oscVal1.equals( "/drawPlatesCoordError" )) {  drawPlatesCoordError = int(oscVal2) ; }  // 0-127


    // drawTiles
    if(oscVal1.equals( "/drawTilesToggle" )) {  drawTilesToggle = boolean(int(oscVal2)) ; }

    if(oscVal1.equals( "/drawTilesBgHue" )) {  drawTilesBgHue = int(oscVal2) ; }
    if(oscVal1.equals( "/drawTilesBgSat" )) {  drawTilesBgSat = int(oscVal2) ; }
    if(oscVal1.equals( "/drawTilesBgBri" )) {  drawTilesBgBri = int(oscVal2) ; }
    if(oscVal1.equals( "/drawTilesHue" )) {  drawTilesHue = int(oscVal2) ; }
    if(oscVal1.equals( "/drawTilesSat" )) {  drawTilesSat = int(oscVal2) ; }
    if(oscVal1.equals( "/drawTilesBri" )) {  drawTilesBri = int(oscVal2) ; }

    if(oscVal1.equals( "/drawTilesHueDistance" )) {  drawTilesHueDistance = int(oscVal2) ; }
    if(oscVal1.equals( "/drawTilesBlendMode" )) {  drawTilesBlendMode = int(oscVal2) ; }

    if(oscVal1.equals( "/drawTilesNumX" )) {  drawTilesNumX = int(oscVal2) ; }
    if(oscVal1.equals( "/drawTilesNumY" )) {  drawTilesNumY = int(oscVal2) ; }

    if(oscVal1.equals( "/drawTilesTexBank" )) {  drawTilesTexBank = int(oscVal2) ; }
    if(oscVal1.equals( "/drawTilesTexId" )) {  drawTilesTexId = int(oscVal2) ; }
    if(oscVal1.equals( "/drawTilesTexSpeedX" )) {  drawTilesTexSpeedX = oscVal2 ; }
    if(oscVal1.equals( "/drawTilesTexSpeedY" )) {  drawTilesTexSpeedY = oscVal2 ; }
    if(oscVal1.equals( "/drawTilesOverlap" )) {  drawTilesOverlap = oscVal2 ; }


    // drawImageBlender
    if(oscVal1.equals( "/drawImageBlenderToggle" )) { drawImageBlenderToggle = boolean(int(oscVal2)) ; } // 130-127 = 3 @ chan2

    if(oscVal1.equals( "/drawImageBlenderBank" )) { drawImageBlenderBank = int(oscVal2) ; } // 131-127 = 4
    if(oscVal1.equals( "/drawImageBlenderID" )) { drawImageBlenderID = int(oscVal2) ; } //5

    if(oscVal1.equals( "/iblNum" )) { iblNum = int(oscVal2) ; } // 6
    if(oscVal1.equals( "/iblX" )) { iblX = ((oscVal2-64) / 64.0) * width/2 ; } // 7  int( ((oscVal2-64) / 64.0) * width/2 ); }
    if(oscVal1.equals( "/iblY" )) { iblY = ((oscVal2-64) / 64.0) * width/2 ; } // 8
    if(oscVal1.equals( "/iblWidth" )) { iblWidth = oscVal2 * oscVal2 * 0.2 * norm(width, 0, width) ; } // 9  int(oscVal2 * oscVal2 * 0.05 * norm(width, 0, width));
    if(oscVal1.equals( "/iblHeight" )) { iblHeight = oscVal2 * oscVal2 * 0.1 * norm(height, 0, height) ; } // 10

    if(oscVal1.equals( "/iblRot" )) { iblRot =  radians(oscVal2 * 360 / 120) ; } // 11
    //if(oscVal1.equals( "139" )) { iblSpeedX = oscVal2 ; } // 12
    //if(oscVal1.equals( "140" )) { iblSpeedY = oscVal2 ; } // 13
    //if(oscVal1.equals( "141" )) { iblSpeedXfactor = ((oscVal2-64) * abs(oscVal2-64) * 0.6) ; } // 14
    //if(oscVal1.equals( "142" )) { iblSpeedYfactor = ((oscVal2-64) * abs(oscVal2-64) * 0.6) ; } // 15

    //if(oscVal1.equals( "143" )) { iblTexX =  ((oscVal2 - 64) / 64.0) * width / 2 ; } // 16
    //if(oscVal1.equals( "144" )) { iblTexY =  ((oscVal2 - 64) / 64.0) * height / 2 ; } // 17
    if(oscVal1.equals( "/iblTexWidth" )) { iblTexWidth = (oscVal2 - 64) * oscVal2 ; } // 18
    if(oscVal1.equals( "/iblTexHeight" )) { iblTexHeight = (oscVal2 - 64) * oscVal2 ; } // 19

    //if(oscVal1.equals( "147" )) { iblTexSpeedX = oscVal2 ; } // 20
    //if(oscVal1.equals( "148" )) { iblTexSpeedY = oscVal2 ; } // 21
    if(oscVal1.equals( "/iblTexSpeedXfactor" )) { iblTexSpeedXfactor = ((oscVal2-64) * abs(oscVal2-64) * 0.6) ; } // 22
    if(oscVal1.equals( "/iblTexSpeedYfactor" )) { iblTexSpeedYfactor = ((oscVal2-64) * abs(oscVal2-64) * 0.6) ; } // 23

    if(oscVal1.equals( "/iblH" )) { iblH = int(oscVal2) ; } // 24
    if(oscVal1.equals( "/iblS" )) { iblS = int(oscVal2) ; } // 25
    if(oscVal1.equals( "/iblB" )) { iblB = int(oscVal2) ; } // 26
    if(oscVal1.equals( "/iblA" )) { iblA = int(oscVal2) ; } // 27
    if(oscVal1.equals( "/iblBflicker" )) { iblBflicker = int(oscVal2) ; } // 28

    if(oscVal1.equals( "/iblItX" )) { iblItX = ((oscVal2-64) * abs(oscVal2-64) * 0.1) ; } // 29
    if(oscVal1.equals( "/iblItY" )) { iblItY = ((oscVal2-64) * abs(oscVal2-64) * 0.1) ; } // 30
    if(oscVal1.equals( "/iblItTexX" )) { iblItTexX = oscVal2 * 4 ; } // 31
    if(oscVal1.equals( "/iblItTexY" )) { iblItTexY = oscVal2 * 4; } // 32
    if(oscVal1.equals( "/iblItRot" )) { iblItRot = radians(oscVal2) ; } // 33


    // playVideo    
    if(oscVal1.equals( "/playVideoToggle" )) {  playVideoToggle = boolean(int(oscVal2)); }
    if(oscVal1.equals( "/playVideoBank" )) {  playVideoBank = int(oscVal2); }
    if(oscVal1.equals( "/playVideoID" )) {  playVideoID = int(oscVal2); }
    if(oscVal1.equals( "/playVideoJump" )) {  playVideoJump = int(oscVal2); }
    if(oscVal1.equals( "/playVideoPausePlay" )) {  playVideoPausePlay = boolean(int(oscVal2)); }
    if(oscVal1.equals( "/playVideoLoop" )) {  playVideoPausePlay = boolean(int(oscVal2)); }
    if(oscVal1.equals( "/playVideoHue" )) {  playVideoHue = int(oscVal2); }
    if(oscVal1.equals( "/playVideoSaturation" )) {  playVideoSaturation = int(oscVal2); }
    if(oscVal1.equals( "/playVideoBrightness" )) {  playVideoBrightness = int(oscVal2); }
    if(oscVal1.equals( "/playVideoAlpha" )) {  playVideoAlpha = int(oscVal2); } //
    if(oscVal1.equals( "/playVideoSpeed" )) {  playVideoSpeed = int(oscVal2); } //

    // test picture
    if(oscVal1.equals( "/testPictureToggle" )) {  testPictureToggle = boolean(int(oscVal2)); }
  }

  // debug:
  print("### OSC | typetag: " + theOscMessage.typetag() + " " + theOscMessage.addrPattern());
  println(" " + oscVal1 + " " + oscVal2); 

    return;
}



