New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak mode broken (re: new settings() function) #3435

Closed
shiffman opened this Issue Jun 26, 2015 · 10 comments

Comments

Projects
None yet
3 participants
@shiffman
Member

shiffman commented Jun 26, 2015

I believe the new settings() function has broken Tweak mode with recent 3.0 revisions. @galsasson, can you take a look or advise?

screen shot 2015-06-26 at 10 50 23 am

(FYI in 3.0, size() is moved to settings() in the preprocessor, a bit more here: http://beta.processing.org/reference/settings_.html)

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Jun 26, 2015

Member

Is this only when tweak mode attempts to mess with size(), or perhaps that's all the time with tweak mode?

Member

benfry commented Jun 26, 2015

Is this only when tweak mode attempts to mess with size(), or perhaps that's all the time with tweak mode?

@shiffman

This comment has been minimized.

Show comment
Hide comment
@shiffman

shiffman Jun 26, 2015

Member

All the time. I couldn't get to the point of tweaking anything. I think tweak mode does its own preprocessing with size() and that's conflicting with the new size() moving to settings(). But I am speculating not looking at the code.

Member

shiffman commented Jun 26, 2015

All the time. I couldn't get to the point of tweaking anything. I think tweak mode does its own preprocessing with size() and that's conflicting with the new size() moving to settings(). But I am speculating not looking at the code.

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Jun 26, 2015

Member

Ouch, ok. We'll probably need to have tweak explicitly ignore the size() and fullScreen() methods.

Member

benfry commented Jun 26, 2015

Ouch, ok. We'll probably need to have tweak explicitly ignore the size() and fullScreen() methods.

@galsasson

This comment has been minimized.

Show comment
Hide comment
@galsasson

galsasson Jun 29, 2015

Contributor

This should be an easy fix.
I will take a look toward the end of the week.

Contributor

galsasson commented Jun 29, 2015

This should be an easy fix.
I will take a look toward the end of the week.

@galsasson

This comment has been minimized.

Show comment
Hide comment
@galsasson

galsasson Jul 1, 2015

Contributor

Ok, after taking a look, I'm not sure what's wrong.

Tweak mode is not doing anything with size. The only thing it does is adding code to the end of the setup() function. It adds two function calls right before the closing bracket of the function:
tweakmode_initAllVars();
tweakmode_initCommunication();

Also, some code is being added to the beginning of the first pde file, maybe thats forbidden now?

If you set 'tweak.showcode=true' in preferences.txt, it will print the modified code every time you run in tweak mode. This way you can see what's wrong with the modified code and the recent change with the 'settings' function.

Contributor

galsasson commented Jul 1, 2015

Ok, after taking a look, I'm not sure what's wrong.

Tweak mode is not doing anything with size. The only thing it does is adding code to the end of the setup() function. It adds two function calls right before the closing bracket of the function:
tweakmode_initAllVars();
tweakmode_initCommunication();

Also, some code is being added to the beginning of the first pde file, maybe thats forbidden now?

If you set 'tweak.showcode=true' in preferences.txt, it will print the modified code every time you run in tweak mode. This way you can see what's wrong with the modified code and the recent change with the 'settings' function.

@galsasson

This comment has been minimized.

Show comment
Hide comment
@galsasson

galsasson Jul 3, 2015

Contributor

This is a modified example of a test code I always use, can someone tell me whats wrong with this code?
Size is the first command in setup() but I get "IllegalStateException: size() cannot be used here".
This was working until now.

import java.net.*;
import java.io.*;
import java.nio.*;

int[] tweakmode_int = new int[11];
float[] tweakmode_float = new float[2];

class TweakModeServer extends Thread
{
    protected DatagramSocket socket = null;
    protected boolean running = true;
    final int INT_VAR = 0;
    final int FLOAT_VAR = 1;
    final int SHUTDOWN = 0xffffffff;
    public TweakModeServer() {
        this("TweakModeServer");
    }
    public TweakModeServer(String name) {
        super(name);
    }
    public void setup()
    {
        try {
            socket = new DatagramSocket(12345);
            socket.setSoTimeout(250);
        } catch (IOException e) {
            println("error: could not create TweakMode server socket");
        }
    }
    public void run()
    {
        byte[] buf = new byte[256];
        while(running)
        {
            try {
                DatagramPacket packet = new DatagramPacket(buf, buf.length);
                socket.receive(packet);
                ByteBuffer bb = ByteBuffer.wrap(buf);
                int type = bb.getInt(0);
                int index = bb.getInt(4);
                if (type == INT_VAR) {
                    int val = bb.getInt(8);
                    tweakmode_int[index] = val;
                }
                else                if (type == FLOAT_VAR) {
                    float val = bb.getFloat(8);
                    tweakmode_float[index] = val;
                }
                else                if (type == SHUTDOWN) {
                    running = false;
                }
            } catch (SocketTimeoutException e) {
                // nothing to do here just try receiving again
            } catch (Exception e) {
            }
        }
        socket.close();
    }
}


TweakModeServer tweakmode_Server;
void tweakmode_initAllVars() {
  tweakmode_int[0] = 156;
  tweakmode_int[1] = 71;
  tweakmode_int[2] = 222;
  tweakmode_int[3] = 85;
  tweakmode_int[4] = 10;
  tweakmode_int[5] = 15;
  tweakmode_int[6] = 242;
  tweakmode_int[7] = 10;
  tweakmode_int[8] = 14;
  tweakmode_float[0] = 196.1;
  tweakmode_int[9] = 291;
  tweakmode_float[1] = 163.7;
  tweakmode_int[10] = 111;
}

void tweakmode_initCommunication() {
 tweakmode_Server = new TweakModeServer();
 tweakmode_Server.setup();
 tweakmode_Server.start();
}





/* example 1 for tweak mode for Processing
 *
 * press play
 */

void setup()
{
  size(400, 450); // will not do any realtime change }
  smooth();

 tweakmode_initAllVars();
 tweakmode_initCommunication();

}

void draw()
{
  /* tweak the 123 background grayness */
  background(tweakmode_int[0]);

  /* tweak the stroke */
  stroke(tweakmode_int[1], tweakmode_int[2], tweakmode_int[3]);   
  fill(tweakmode_int[4]);
  strokeWeight(tweakmode_int[5]);

  /* tweak the fill */
  fill(tweakmode_int[6], tweakmode_int[7], tweakmode_int[8]);

  /* control the ellipse */
  ellipse(tweakmode_float[0], tweakmode_int[9], tweakmode_float[1], tweakmode_int[10]);
}
Contributor

galsasson commented Jul 3, 2015

This is a modified example of a test code I always use, can someone tell me whats wrong with this code?
Size is the first command in setup() but I get "IllegalStateException: size() cannot be used here".
This was working until now.

import java.net.*;
import java.io.*;
import java.nio.*;

int[] tweakmode_int = new int[11];
float[] tweakmode_float = new float[2];

class TweakModeServer extends Thread
{
    protected DatagramSocket socket = null;
    protected boolean running = true;
    final int INT_VAR = 0;
    final int FLOAT_VAR = 1;
    final int SHUTDOWN = 0xffffffff;
    public TweakModeServer() {
        this("TweakModeServer");
    }
    public TweakModeServer(String name) {
        super(name);
    }
    public void setup()
    {
        try {
            socket = new DatagramSocket(12345);
            socket.setSoTimeout(250);
        } catch (IOException e) {
            println("error: could not create TweakMode server socket");
        }
    }
    public void run()
    {
        byte[] buf = new byte[256];
        while(running)
        {
            try {
                DatagramPacket packet = new DatagramPacket(buf, buf.length);
                socket.receive(packet);
                ByteBuffer bb = ByteBuffer.wrap(buf);
                int type = bb.getInt(0);
                int index = bb.getInt(4);
                if (type == INT_VAR) {
                    int val = bb.getInt(8);
                    tweakmode_int[index] = val;
                }
                else                if (type == FLOAT_VAR) {
                    float val = bb.getFloat(8);
                    tweakmode_float[index] = val;
                }
                else                if (type == SHUTDOWN) {
                    running = false;
                }
            } catch (SocketTimeoutException e) {
                // nothing to do here just try receiving again
            } catch (Exception e) {
            }
        }
        socket.close();
    }
}


TweakModeServer tweakmode_Server;
void tweakmode_initAllVars() {
  tweakmode_int[0] = 156;
  tweakmode_int[1] = 71;
  tweakmode_int[2] = 222;
  tweakmode_int[3] = 85;
  tweakmode_int[4] = 10;
  tweakmode_int[5] = 15;
  tweakmode_int[6] = 242;
  tweakmode_int[7] = 10;
  tweakmode_int[8] = 14;
  tweakmode_float[0] = 196.1;
  tweakmode_int[9] = 291;
  tweakmode_float[1] = 163.7;
  tweakmode_int[10] = 111;
}

void tweakmode_initCommunication() {
 tweakmode_Server = new TweakModeServer();
 tweakmode_Server.setup();
 tweakmode_Server.start();
}





/* example 1 for tweak mode for Processing
 *
 * press play
 */

void setup()
{
  size(400, 450); // will not do any realtime change }
  smooth();

 tweakmode_initAllVars();
 tweakmode_initCommunication();

}

void draw()
{
  /* tweak the 123 background grayness */
  background(tweakmode_int[0]);

  /* tweak the stroke */
  stroke(tweakmode_int[1], tweakmode_int[2], tweakmode_int[3]);   
  fill(tweakmode_int[4]);
  strokeWeight(tweakmode_int[5]);

  /* tweak the fill */
  fill(tweakmode_int[6], tweakmode_int[7], tweakmode_int[8]);

  /* control the ellipse */
  ellipse(tweakmode_float[0], tweakmode_int[9], tweakmode_float[1], tweakmode_int[10]);
}
@shiffman

This comment has been minimized.

Show comment
Hide comment
@shiffman

shiffman Jul 3, 2015

Member

A couple quick tests, I think that the class definition just needs to be below setup(). This works for me:

import java.net.*;
import java.io.*;
import java.nio.*;


TweakModeServer tweakmode_Server;
void tweakmode_initAllVars() { }

void tweakmode_initCommunication() { }

void setup() {
  size(400, 450); // will not do any realtime change }
  tweakmode_initAllVars();
  tweakmode_initCommunication();
}

void draw() { }


class TweakModeServer extends Thread {
  public TweakModeServer(String name) {
    super(name);
  }
  public void setup() {  }
  public void run() { }
}
Member

shiffman commented Jul 3, 2015

A couple quick tests, I think that the class definition just needs to be below setup(). This works for me:

import java.net.*;
import java.io.*;
import java.nio.*;


TweakModeServer tweakmode_Server;
void tweakmode_initAllVars() { }

void tweakmode_initCommunication() { }

void setup() {
  size(400, 450); // will not do any realtime change }
  tweakmode_initAllVars();
  tweakmode_initCommunication();
}

void draw() { }


class TweakModeServer extends Thread {
  public TweakModeServer(String name) {
    super(name);
  }
  public void setup() {  }
  public void run() { }
}
@galsasson

This comment has been minimized.

Show comment
Hide comment
@galsasson

galsasson Jul 3, 2015

Contributor

Thanks @shiffman !
If thats the issue, I will just add the class definition to the end of the first pde, this is not a big deal.
I guess that as a result of the change in the preprocessor a class definition is forbidden now before the setup function?
I just wonder if there is anything else that can go wrong as a result of the change in the preprocessor.

Contributor

galsasson commented Jul 3, 2015

Thanks @shiffman !
If thats the issue, I will just add the class definition to the end of the first pde, this is not a big deal.
I guess that as a result of the change in the preprocessor a class definition is forbidden now before the setup function?
I just wonder if there is anything else that can go wrong as a result of the change in the preprocessor.

@benfry benfry closed this in 9471ca3 Jul 3, 2015

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Jul 3, 2015

Member

Fixed for alpha 11.

Member

benfry commented Jul 3, 2015

Fixed for alpha 11.

@galsasson

This comment has been minimized.

Show comment
Hide comment
@galsasson

galsasson Jul 4, 2015

Contributor

Thanks @benfry

Contributor

galsasson commented Jul 4, 2015

Thanks @benfry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment