We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Scale variables, and return integer!
Page Index Toggle Pages: 1
Scale variables, and return integer! (Read 882 times)
Scale variables, and return integer!
Jan 14th, 2010, 3:03pm
 
Hi,

just working on a simple XY-controller that sends MIDI control change messages. The mouseX and mouseY have to be scaled to 0-127 (MIDI range) and integer values. The problem is that the map() function returns floats which the MIDI controller send function doesn't accept. Any ideas how to scale a variable and return integer? Here's the code (it won't work!):

import rwmidi.*;
MidiOutput output;
int mousex;
int mousey;
void setup(){
 size(500,500);
 smooth();

}
void draw(){
   output = RWMidi.getOutputDevices()[0].createOutput();
 background(50);
 int CCnumx=10;
 int CCnumy=11;
 mousex=map(mouseX,0,127);
 mousey=map(mouseY,0,127);
 output.sendController(2,CCnumx,mousex);
 output.sendController(1,CCnumy,mousey);
 fill(175);
 ellipse(mouseX,mouseY,10,10);
}

Re: Scale variables, and return integer!
Reply #1 - Jan 14th, 2010, 3:14pm
 
mousex= (int)map(mouseX,0,127);
Re: Scale variables, and return integer!
Reply #2 - Jan 14th, 2010, 4:13pm
 
Thanks man!
Re: Scale variables, and return integer!
Reply #3 - Jan 14th, 2010, 4:46pm
 
try this:

mousex = round(map(mouseX, 0, width, 0, 127));

map takes 5 parameters.
if you use round() it will give you values from 0 up to 127. Using int() or (int) the maximum will be 126.


Page Index Toggle Pages: 1