Go Back   Cockos Confederated Forums > REAPER Forums > JSFX and ReaScript Discussion

Reply
 
Thread Tools Display Modes
Old 03-24-2011, 05:58 PM   #41
Mich
Human being with feelings
 
Join Date: May 2009
Posts: 1,265
Default

Quote:
Originally Posted by caseyjames View Post
Not that I'd be able to write a handler for them, but is it not possible to write something within JS to read a midi file? Is it not able to load arbitrary files, even if it can't cope with them?
Unless Cockos changed something and they forgot to update the JS documentation, yes.

Here are all available file functions in JS:
http://www.reaper.fm/sdk/js/js.php#cat_file

MIDI is not among then and neither is arbitrary file access. Only wav, ogg and specially formated txt files.
Mich is offline   Reply With Quote
Old 03-24-2011, 06:53 PM   #42
groundhum
Human being with feelings
 
groundhum's Avatar
 
Join Date: Jan 2011
Location: Finger Lakes, NY
Posts: 49
Default

Doesn't file_mem() read from any open file? I'm just asking; the spec implies it.
__________________
Michael Rees, composer &c.
extraneous data
groundhum is offline   Reply With Quote
Old 03-24-2011, 08:23 PM   #43
Mich
Human being with feelings
 
Join Date: May 2009
Posts: 1,265
Default

Quote:
Originally Posted by groundhum View Post
Doesn't file_mem() read from any open file? I'm just asking; the spec implies it.
Maybe, but I don't think JS allowa you to open any other files than wav, ogg and txt. I could be wrong though, best thing would be you go and try to open a MIDI file and see whether file_mem() returns something usable, however I doubt it will work because similar requests were already made multiple times, e.g.: http://forum.cockos.com/showthread.php?t=75323 but the answer todate has (sadly) always been no you can't read arbitrary files with JS.
Mich is offline   Reply With Quote
Old 03-24-2011, 08:43 PM   #44
caseyjames
Human being with feelings
 
caseyjames's Avatar
 
Join Date: Jul 2009
Posts: 607
Default

Has there been any mention of a JS 2 anywhere on the horizon?
caseyjames is offline   Reply With Quote
Old 05-12-2011, 03:24 AM   #45
vocalid
Human being with feelings
 
vocalid's Avatar
 
Join Date: Sep 2009
Location: Middle of nowhere (where the cheese comes from)
Posts: 483
Default Displaying sliders without text

I don't know if anyone has ever had this problem:

You want to insert a slider but not have a desription left of it? ...space doesn't work, it won't display the slider.

Solution: insert ASCII code 129 -> hold alt down while pressing 0129 on the keyboard number pad

(took me ages of trying out stuff to find it)

Last edited by vocalid; 05-12-2011 at 03:36 AM.
vocalid is offline   Reply With Quote
Old 09-23-2011, 03:21 AM   #46
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 12,362
Default Defininig arrays

I used to run into problems defining arrays in JS FX, losing track of how the memory was being used and inadvertently reusing or overwriting memory slots.

I've come up with a fairly fool-proof syntax for defining arrays:
-- define the start address, number of items and end address together
-- for the next array, its start address = the end address of the previous array
-- each array item can consist of multiple elements
-- include any initialisation or constants (indented, for clarity)

Here is an example:

Code:
// -----------------------------------------------------------
    in_buffs = 1024;					// start of array
    noofbuffs = 256;					// number of items in array
    end_in_buffs = in_buffs + noofbuffs;		// end of array

        in_buffs[0] =  21; in_buffs[1] =  25; etc 	// initialisation of array

// -----------------------------------------------------------
    label_X = end_in_buffs;				// start of next array, = end of previous array	
    nooflabs = 32;						// number of items in array
    label_Y = label_X + nooflabs;
    label_Z = label_Y + nooflabs;
    end_labels = label_Z + nooflabs;			// end of array

        label_X[0] = 20; label_X[1] = 50; etc	// initialisation of array
        label_Y[0] = 110; label_Y[1] = 57; etc
        label_Z[0] = 40; label_Z[1] = 60; etc
 
// -----------------------------------------------------------
    chan_state = end_labels;				// start of next array, = end of previous array
        OFF = 0;						// constants for buff_state
        ON = 1;
   noofchans = 16;
   end_chan_states = chan_state + noofchans;	// end of array
 
        memset(chan_state, OFF, noofchans);	// initialisation of array (dest, value, length)
        chan_state[2] = ON;

// -----------------------------------------------------------
__________________
DarkStar ... interesting, if true.
My top 40 FRs, as voted by you
DarkStar is offline   Reply With Quote
Old 01-14-2013, 06:16 AM   #47
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 2,475
Default List import library

I made a suite of functions for managing lists of items in memory. Hopefully some people might find it useful .

Details and discussion at http://forum.cockos.com/showthread.p...23#post1104623
IXix is offline   Reply With Quote
Old 04-25-2013, 11:40 PM   #48
bang
Human being with feelings
 
bang's Avatar
 
Join Date: Jul 2006
Posts: 547
Default newJs pseudo-object parameters

hello all!

seems that the main limitation of newJs pseudo-objects is that inside a function "this.foo" is all there is. there's no inbuilt way to refer to "that.foo". here's my current workaround technique:
Code:
function rgbapush()
  instance( r, g, b, a )
(
  stack_push( a );
  stack_push( b );
  stack_push( g );
  stack_push( r );
);

function rgbapop()
  instance( r, g, b, a )
(
  stack_pop( r );
  stack_pop( g );
  stack_pop( b );
  stack_pop( a );
);

// a.rgbapush(); b.rgbapush();
function rgbamix( mix ) // thread safe
  instance( r, g, b, a ) local( mix1 )
(
  mix1= 1-mix;
  this.rgbapop(); // this= b.rgbapush();
  // keep in sync w/ rgbapop()
  r= stack_pop() * mix1 + r * mix; //stack_pop( a.r );
  g= stack_pop() * mix1 + g * mix; //stack_pop( a.g );
  b= stack_pop() * mix1 + b * mix; //stack_pop( a.b );
  a= stack_pop() * mix1 + a * mix; //stack_pop( a.a );
);

/*** alas, doesn't work:
// a.rgbapush(); b.rgbapush();
function rgbamix2( mix )
  instance( r, g, b, a )
  local(a1, b1)
(
  mix1= 1-mix;
  b1.rgbapop(); a1.rgbapop();
  r= a1.r * mix1 + b1.r * mix;
  g= a1.g * mix1 + b1.g * mix;
  b= a1.b * mix1 + b1.b * mix;
  a= a1.a * mix1 + b1.a * mix;
); ***/
anyone have anything better than this?

enjoy! /dan
bang is offline   Reply With Quote
Old 05-26-2013, 05:56 AM   #49
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Midi automateable sends. Only via OSC.
Posts: 1,119
Default

Is there a copy of this thread, but ONLY for midi, no audio at all. Note speed detection, note duration manipulation, velocity manipulation, midi channel filtered processing, never hanging notes no matter what you do = note hanging prevention, note transposition, midi looping with velocity fade out per note using various fade out functions, midi looping with cc7 fade out using various fade out functions, note speed channelizer, polyphony channelizer, keyboard splitter into 3 zones per midi channel, chord info, key snap, arp!0

Tips and tricks, snippets, ideas for midi processing with zero audio processing.
__________________
Volume mixing via jogwheeling with mouseovering. Yeah!
Check my Reaper real-time usage ideas.
boreg made it, never hanging notes in Reaper again! Thanks boreg! boreg & bang.
TonE is offline   Reply With Quote
Old 05-26-2013, 12:32 PM   #50
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 7,837
Default

Quote:
Originally Posted by bang View Post
Code:
/*** alas, doesn't work:
// a.rgbapush(); b.rgbapush();
function rgbamix2( mix )
  instance( r, g, b, a )
  local(a1, b1)
(
  mix1= 1-mix;
  b1.rgbapop(); a1.rgbapop();
  r= a1.r * mix1 + b1.r * mix;
  g= a1.g * mix1 + b1.g * mix;
  b= a1.b * mix1 + b1.b * mix;
  a= a1.a * mix1 + b1.a * mix;
); ***/
anyone have anything better than this?
If you changed local(a1,b1) to instance(a1,b1), I believe this might work! local namespace support would be nice, too, but it isn't currently supported.
Justin is offline   Reply With Quote
Old 05-26-2013, 01:30 PM   #51
bang
Human being with feelings
 
bang's Avatar
 
Join Date: Jul 2006
Posts: 547
Default

Quote:
Originally Posted by Justin View Post
If you changed local(a1,b1) to instance(a1,b1), I believe this might work! local namespace support would be nice, too, but it isn't currently supported.
yes. but won't we end up with <psuedo-object>.a1.r/g/b/a and <psuedo-object>.b1.r/g/b/a for every psuedo-object which uses rgbamix2()? i guess i haven't wanted to load up the Js namespace any more than i need to. it already gets to be a pretty massive variables list in the debug window. :^)

and fwiw... what i'd really love to see someday is a way to alias psuedo-object namespaces inside functions. something like:
Code:
// rgbamix2( mix, a, b )
function rgbamix2( mix, @a1, @b1 )
  instance( r, g, b, a )
(
  mix1= 1-mix;
  r= a1.r * mix1 + b1.r * mix; // r= a.r * mix1 + b.r * mix
  g= a1.g * mix1 + b1.g * mix;
  b= a1.b * mix1 + b1.b * mix;
  a= a1.a * mix1 + b1.a * mix;
);
just sayin'... :^)

enjoy! /dan

ps- also fwiw, stack_push()/pop() are awesomely useful generally. thanks so much for those.

Last edited by bang; 05-26-2013 at 01:35 PM. Reason: ps
bang is offline   Reply With Quote
Old 10-10-2013, 11:49 PM   #52
Hubi
Human being with feelings
 
Join Date: Oct 2010
Posts: 56
Default

A simple button maker function:

Code:
function button(state x1 y1 x2 y2 r g b)
  (
  gfx_x = x1;
  gfx_y = y1;
  gfx_r =r;gfx_b=b;gfx_g=g;
  (mouse_x > x1 && mouse_x < x1+x2 && mouse_y > y1 && mouse_y < y1+y2) ? (
    gfx_r =r+0.05;gfx_b=b+0.05;gfx_g=g+0.05; 
    mouse_cap == 1 ? (
      state = 1;
      gfx_r =r+0.2;gfx_b=b+0.2;gfx_g=g+0.2;
      );  
    ) : (
    state = 0; 
  ); 
  gfx_rectto(gfx_x+x2,gfx_y+y2); 
  state;
  );
Code:
button_clicked = button(state,20,20,40,20,0.6,0.6,0.6);
state returns "1" if the button is clicked, otherwise it is "0"
x1 and y1 are the position of the left top corner
x2 and y2 are the size of the button
r,g,b color


it shows if the mouse hovers over the button and if it is clicked

regards
Hubi
Hubi is offline   Reply With Quote
Old 10-17-2013, 01:15 PM   #53
reapercurious
Human being with feelings
 
reapercurious's Avatar
 
Join Date: Jul 2007
Posts: 1,134
Default

Quote:
Originally Posted by liteon View Post
a fast linear congruential generator (or specifically the park-miller variation) is described below.

basic algorithm:
Code:
@init
rnd=1;
@sample
rnd=rnd*a%m;
but the main problem is the range in our case, since with some of the common lcg parameters we go out of range:
Code:
@init
rnd=1;
@sample
rnd=rnd*16807%2147483647;
// call 0
// 1*16807%2147483647=16807
// call 1
// 16807*16807%2147483647=2824275249
// call 2
// 2824275249*16807%2147483647=1 -> out of range prevention
therefore a larger modulus cannot be used, such as the 2^31-1 -> 'marsenne prime'

so here are some parameters i've calculated based on the "zx-spectrum" multiplier,(77) but with much larger modulus.

Code:
//all with initial seed 1
rnd0*=77;                     //$x4D
rnd0%=16777219;               //$x1000003=2^24+3
rnd1*=76;                     //$x4C
rnd1%=16777221;               //$x1000005=2^24+5
rnd2*=77;                     //$x4D
rnd2%=8388609;                //$x800001=2^23+1
so basically all that is needed is a scaling factor in the end:
Code:
//full code
@init
rnd=1;
@sample
rnd*=77;
rnd%=16777219;
spl0=rnd*0.0000000593; //scale down to 0-1 range
comparison with the marsenne twister implementation in rand().
100 executions of rand() = 61% cpu
100 executions of one recursion lane lcg = 26% cpu

@gfx plots (ermm...30sec freerun)

two rand() x,y:



two recursions lanes lcg for x,y:



the more expensive gaussian noise version as a bonus:
Code:
//gaussian version
@init
rnd0=rnd1=rnd2=1;
@sample
rnd0*=77;
rnd0%=16777219;
rnd1*=76;
rnd1%=16777221;
rnd2*=77;
rnd2%=8388609;
spl0=(rnd0+rnd1+rnd2)*0.00000002403333333333333; //.... *k
//k=(1/3*0.0000000721)

----
lubomir
real world user-understandable application would be appreciated on these snippets, otherwise they are only useful to people who understand terms and concepts that are four orders elevated in mean sophistication.
reapercurious is offline   Reply With Quote
Old 10-20-2013, 04:46 AM   #54
chilledpanda
Human being with feelings
 
chilledpanda's Avatar
 
Join Date: Jan 2013
Location: United Kingdom
Posts: 26
Default

Here's a technique I found useful for debugging, by watching local memory akin to memory watch widows in professional debuggers.

First set up a slider (I use 64 as it's he last one),
This slider allows you to view local 0-to 2048,

slider64:0<0,2048,16>MEMWATCH LOC

Then change/add @slider to read the slider and set the memwatchvariable

@slider
//debugging code
memwatch = floor(slider64);


Add the follow to the @gfx uppdate block this constantly updates so allows us to constantly update the mem watch variables

@gfx

//debug code
memwatch_00 = memwatch[0];
memwatch_01 = memwatch[1];
memwatch_02 = memwatch[2];
memwatch_03 = memwatch[3];
memwatch_04 = memwatch[4];
memwatch_05 = memwatch[5];
memwatch_06 = memwatch[6];
memwatch_07 = memwatch[7];
memwatch_08 = memwatch[8];
memwatch_09 = memwatch[9];
memwatch_10 = memwatch[10];
memwatch_11 = memwatch[11];
memwatch_12 = memwatch[12];
memwatch_13 = memwatch[13];
memwatch_14 = memwatch[14];
memwatch_15 = memwatch[15];



Then in the JS development environment editor make sure the auto refresh is ticked under the left window and then locate the memwatch variables.

Move the slider and see the memory locations update in steps of 16 values.
__________________
-------------------------------------------------------------------------------
http://soundcloud.com/chilled-panda
chilledpanda is offline   Reply With Quote
Old 02-04-2014, 11:09 AM   #55
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Evanston, IL
Posts: 1,083
Default

this page: https://ccrma.stanford.edu/~craig/ar...essenmidi.html seems to have some explanation on midi messages, but does not exactly correlate to JS explanation: http://www.reaper.fm/sdk/js/midi.php#js_midi

Is there a comprehensive list of midi messages/parameters? Like note on/off, channel pressure, midi cc, etc.
__________________
Soundemote Junebug Kit - a deeply sampled Snare, Kick, and Hat for breakbeat and drum'n'bass.
Argitoth is online now   Reply With Quote
Old 02-04-2014, 11:25 AM   #56
James HE
Human being with feelings
 
James HE's Avatar
 
Join Date: Mar 2007
Posts: 3,277
Default

Quote:
Originally Posted by Argitoth View Post

Is there a comprehensive list of midi messages/parameters? Like note on/off, channel pressure, midi cc, etc.
here.

http://www.midi.org/techspecs/midimessages.php
__________________
James HE - Solitude for the Paranoid, Joy for the Unexcited
on itunes and Spotify and facebook
James HE is offline   Reply With Quote
Old 05-30-2014, 10:36 AM   #57
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Evanston, IL
Posts: 1,083
Default

check this out, 0 to 1 taper, log-like to exp-like and everything inbetween

http://www.mathopenref.com/graphfunc...40425531914894

interactive graph, we should start using this more often.
__________________
Soundemote Junebug Kit - a deeply sampled Snare, Kick, and Hat for breakbeat and drum'n'bass.
Argitoth is online now   Reply With Quote
Old 06-05-2014, 08:52 PM   #58
SaulT
Human being with feelings
 
Join Date: Oct 2013
Location: Seattle, WA
Posts: 184
Default

This is the function that Argitoth is suggesting:

Code:
x = [0, 1]
y = (a*x-x)/(2*a*x-a-1)

range: a = [-1, 1]
a -> 1  log taper
a == 0  linear
a -> -1  reverse log taper
I have an alternative. It is slightly faster to execute but a little harder to dial in precisely.

Code:
x = [0, 1]
y = ((1+a)*x)/(a+x)

range: a can neither be nor be between 0 and -1

a from large positive -> 0.0001...   log taper
a from large negative -> -1.0001...   reverse log taper
http://www.mathopenref.com/graphfunc...0&al=-10&a=-10

Illustration of Tapers

http://www.geofex.com/article_folder...s/pottaper.gif

Last edited by SaulT; 06-05-2014 at 09:08 PM.
SaulT is offline   Reply With Quote
Old 06-11-2014, 01:24 PM   #59
SaulT
Human being with feelings
 
Join Date: Oct 2013
Location: Seattle, WA
Posts: 184
Default

For reference, a quick approximation of the analog hardware audio log taper, with a direct comparison between Argitoth's code and mine. The curves are basically interchangeable.

My code

Code:
function reverseLogTaper(val)
(
  (val*1.1)/(val+0.1);
);

function logTaper(val)
(
  (-0.1*val)/(val-1.1);
);
Argitoth's

Code:
function reverseLogTaper(val)
(
  (-0.85*x-x)/(-1.7*val-0.15);
);

function logTaper(val)
(
  (0.85*val-val)/(1.7*val-1.85);
);
Log (Audio) Taper comparison

http://www.mathopenref.com/graphfunc...=5&bl=-5&b=0.1

Reverse Log (Reverse Audio) Taper comparison

http://www.mathopenref.com/graphfunc...=5&bl=-5&b=0.1
SaulT is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 12:03 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.