Old 09-20-2018, 07:14 PM   #1
brainwreck
Human being with feelings
 
Join Date: Jul 2006
Posts: 20,859
Default Why does jsfx not have a file write function?

What the title says. Obviously, writing to files would be really useful.
__________________
It's time to take a stand against the synthesizer.
brainwreck is offline   Reply With Quote
Old 09-20-2018, 07:43 PM   #2
preferred.nomenclature
Human being with feelings
 
Join Date: Dec 2014
Posts: 371
Default

I’ve never messed wirth any of these, but it looks like file_var() can write to a file, no? https://www.reaper.fm/sdk/js/file.php#js_file
preferred.nomenclature is offline   Reply With Quote
Old 09-21-2018, 07:40 AM   #3
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 346
Default

Quote:
Originally Posted by preferred.nomenclature View Post
I’ve never messed wirth any of these, but it looks like file_var() can write to a file, no? https://www.reaper.fm/sdk/js/file.php#js_file
Unfortunately not - it can only write to preset data in @serialize. There's no way to open a file in "write" mode, as far as I'm aware.

As for the original question "why": I'm not being sarcastic, but I think the answer is pretty much "Justin didn't add it in". There will always be a frontier of features that would be useful in some subset of situations, and it's a judgement call how far to push those boundaries, compared to the complexity (and effort) it introduces.

If you're motivated, there's a Feature Requests sub-forum, you could try and get support (or perhaps answers) there. Probably worth searching if it's already been suggested, so you can bump that with a +1.
__________________
JSFX set | Bandcamp/SoundCloud/Spotify

Last edited by geraintluff; 09-21-2018 at 05:20 PM.
geraintluff is offline   Reply With Quote
Old 09-21-2018, 04:10 PM   #4
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 15,721
Default

The rationale is that JSFX should not be able to write to files! Outside the scope of what they should be permitted to do, as processors...
Justin is offline   Reply With Quote
Old 09-21-2018, 05:38 PM   #5
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 346
Default

Quote:
Originally Posted by Justin View Post
The rationale is that JSFX should not be able to write to files! Outside the scope of what they should be permitted to do, as processors...
Um - so obviously you're the authority on this. But we already have some APIs like export_buffer_to_project() which are slightly outside the "pure state machine" model of an audio processor, but are still useful for creating certain types of audio effect.

This isn't to say that file-write should be included, just that the line isn't completely self-evident from the definition of a "processor".

JSFX is wonderful for writing effects, and I do appreciate that it doesn't cram every imaginable feature in, and focuses on what it's good at. So, I have faith in your judgement on this, and obviously appreciate you making it in the first place.
__________________
JSFX set | Bandcamp/SoundCloud/Spotify
geraintluff is offline   Reply With Quote
Old 09-21-2018, 07:27 PM   #6
eugen2777
Human being with feelings
 
eugen2777's Avatar
 
Join Date: Aug 2012
Posts: 271
Default

This can be a good addition ("undocumented" - thoughtfully)
__________________
ReaScripts
eugen2777 is offline   Reply With Quote
Old 09-21-2018, 09:41 PM   #7
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,686
Default

While I do agree that writing to files (and reading files other than for initialization) is a no-go for such a realtime processor building tool, there might be workarounds.

If gmem would be accessible not only for jsfxes, but also for ReaScripts, and file writing is enabled for those (which run in the environment of the GUI thread), appropriate software could be done. In fact a JSFX already can send out Midi data, theses can be routed by MidiToReaControlPath and received by a ReaScript. Seems to make sense for very small data amounts.

This said, in fact JSFXes already can write to files . A friend of mine uses this in a project he created. Just have the JSFX output an audio stream and then render. If rendering to lossless compressed FLAC, sending out a stream of constants does not take much place besides your useful data. Now you can use appropriate software to decode the data.

Moreover Midi data sent by a JSFX can be saved in the Reaper Project file.

-Michael

Last edited by mschnell; 09-21-2018 at 11:50 PM.
mschnell is offline   Reply With Quote
Old 09-23-2018, 07:11 AM   #8
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

I wondered as well. I would be perfectly happy if I could send over information to/from ReaScripts, as mschnell pointed out.

Even if it were only by extstates. I have tons of great usecases waiting to be ready for such a thing.


In addition, the video-processor-plugin would benefit from such a thing as well. I could add text to textprocessor-plugins better, if I could add the text using extstates, instead of having to seek and replace code in the item/trackstatechunk.
Meo-Ada Mespotine is offline   Reply With Quote
Old 09-23-2018, 12:22 PM   #9
Philbo King
Human being with feelings
 
Philbo King's Avatar
 
Join Date: May 2017
Posts: 3,201
Default

So... is the following text from the jsfx reference guide File I/O page incorrect?

file_mem(handle,offset, length)
Example:

amt=file_mem(handle,offset,len);

This reads (or writes) the block of local memory from(to) the current file. Returns the actual number of items read (or written).

Does "current file" not refer to a disk file? Am I taking something out of context? It is also not clear how to specify a write rather than a read.

I'm becoming quite accomplished at confusion because I practice it so much...
__________________
Tangent Studio - Philbo King
www.soundclick.com/philboking - Audio streams

Last edited by Philbo King; 09-23-2018 at 12:36 PM.
Philbo King is offline   Reply With Quote
Old 09-24-2018, 11:31 AM   #10
brainwreck
Human being with feelings
 
Join Date: Jul 2006
Posts: 20,859
Default

Another use case for file writing would be sampling (not sample playback) straight into a jsfx. Like old-school sampling, rather than first recording samples to a track, slicing, and dragging in each sample. Maybe with transient detection, so as not to have to do manual slicing. In other words, a more immediate workflow for sampling.
__________________
It's time to take a stand against the synthesizer.

Last edited by brainwreck; 09-24-2018 at 11:38 AM.
brainwreck is offline   Reply With Quote
Old 09-24-2018, 01:08 PM   #11
brainwreck
Human being with feelings
 
Join Date: Jul 2006
Posts: 20,859
Default

So then, the samples would be project dependent? That could work, but obviously it would be a bit kludgy to load the jsfx for other projects (open project that has the jsfx, copy it, paste it into a new project (if that would even work).
__________________
It's time to take a stand against the synthesizer.
brainwreck is offline   Reply With Quote
Old 09-24-2018, 01:08 PM   #12
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,686
Default

Quote:
Originally Posted by Philbo King View Post
So... is the following text from the jsfx reference guide File I/O page incorrect?

file_mem(handle,offset, length)
Example:

amt=file_mem(handle,offset,len);

This reads (or writes) the block of local memory from(to) the current file. Returns the actual number of items read (or written).
Some lines above it sais:
Quote:
File I/O and Serialization:
The following functions can be used in the @serialize section or in other sections.

Using with @serialize:
Pass 0 as a handle to various file_*() functions, but do not call file_open() or file_close(). Simple @serialize code will often appear the same for read and write, as file_var(0,x) will read/write x depending on the mode. If you want to have different logic per mode, you can check file_avail(0)>=0 to determine if it is in read mode.

Using in other sections:
file_open() and file_close() can be used to open files for reading in any section.
So AFAIU, writing to a file is only done when saving the project.

-Michael
mschnell is offline   Reply With Quote
Old 09-24-2018, 01:10 PM   #13
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,686
Default

Quote:
Originally Posted by brainwreck View Post
Another use case for file writing would be sampling (not sample playback) straight into a jsfx.
You could store the samples in memory and in @serialize write them to a file when saving the project.

-Michael
mschnell is offline   Reply With Quote
Old 09-24-2018, 01:12 PM   #14
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,686
Default

Quote:
Originally Posted by brainwreck View Post
So then, the samples would be project dependent?
What do you mean by "project" dependent ?
AFAIU, Just the time when writing to a file is restricted, not the location.

-Michael
mschnell is offline   Reply With Quote
Old 09-24-2018, 01:12 PM   #15
brainwreck
Human being with feelings
 
Join Date: Jul 2006
Posts: 20,859
Default

Edit: Nevermind. Must have been some post editing happening.
__________________
It's time to take a stand against the synthesizer.
brainwreck is offline   Reply With Quote
Old 09-24-2018, 01:15 PM   #16
brainwreck
Human being with feelings
 
Join Date: Jul 2006
Posts: 20,859
Default

Quote:
Originally Posted by mschnell View Post
What do you mean by "project" dependent ?
AFAIU, Just the time when writing to a file is restricted, not the location.

-Michael
Oh, I see. So files can be written (and to wherever) then?

Use case: I would want to sample some audio in a jsfx (and save the audio), manipulate it a bit in the jsfx (non-destructively), and save the jsfx state as a preset (where the file is loaded when the jsfx is loaded).
__________________
It's time to take a stand against the synthesizer.

Last edited by brainwreck; 09-24-2018 at 01:22 PM.
brainwreck is offline   Reply With Quote
Old 09-24-2018, 01:45 PM   #17
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,686
Default

Quote:
Originally Posted by brainwreck View Post
So files can be written (and to wherever) then?
I suppose so:
Quote:
handle = file_open(string);
"string" holding a usual OS file specification.

-Michael
mschnell is offline   Reply With Quote
Old 09-24-2018, 01:47 PM   #18
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,686
Default

Quote:
Originally Posted by brainwreck View Post
Edit: Nevermind. Must have been some post editing happening.
Bad habit of mine: post a text and improve it afterwards
-Michael
mschnell is offline   Reply With Quote
Old 09-25-2018, 05:01 PM   #19
brainwreck
Human being with feelings
 
Join Date: Jul 2006
Posts: 20,859
Default

Quote:
Originally Posted by mschnell View Post
Bad habit of mine: post a text and improve it afterwards
-Michael
I am probably worse than anyone at doing that. Funny how more precise we feel that we have to be in text than when speaking in person.
__________________
It's time to take a stand against the synthesizer.
brainwreck is offline   Reply With Quote
Old 06-09-2019, 09:58 AM   #20
Time Waster
Human being with feelings
 
Time Waster's Avatar
 
Join Date: Aug 2013
Location: Bowral, Australia
Posts: 1,638
Default

Has anyone successfully managed to save a block of memory to a file and recall it later? The documentation seems to suggest that it can be done. However it also says that in @serialize you need to use a handle of 0 (file_mem(0,offset,length)), which seems to save it to the project file only, regardless of what file is open. Using a handle other that 0 in @serialize does nothing, as far as I can tell.
__________________
Mal, aka The Wasters of Time
Mal's JSFX: ReaRack2 Modular Synth
Time Waster is offline   Reply With Quote
Old 06-10-2019, 02:00 AM   #21
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

AFAIK you can't write to an external file.
Tale is offline   Reply With Quote
Old 06-11-2019, 01:54 AM   #22
sai'ke
Human being with feelings
 
sai'ke's Avatar
 
Join Date: Aug 2009
Location: NL
Posts: 1,453
Default

Quote:
Originally Posted by mschnell View Post
This said, in fact JSFXes already can write to files . A friend of mine uses this in a project he created. Just have the JSFX output an audio stream and then render. If rendering to lossless compressed FLAC, sending out a stream of constants does not take much place besides your useful data. Now you can use appropriate software to decode the data.

Moreover Midi data sent by a JSFX can be saved in the Reaper Project file.

-Michael
Haha, this is a cool idea. It reminds me of the old tape days. Have to rewind the tape to load the settings
__________________
[Tracker Plugin: Thread|Github|Reapack] | [Routing Plugin: Thread|Reapack] | [More JSFX: Thread|Descriptions|Reapack]
sai'ke is offline   Reply With Quote
Old 06-11-2019, 07:34 PM   #23
Time Waster
Human being with feelings
 
Time Waster's Avatar
 
Join Date: Aug 2013
Location: Bowral, Australia
Posts: 1,638
Default

After posting my previous message, I realised that both presets and FX chains are methods of saving memory dumps. A preset file is a series of memory dumps. An FX chain is a single memory dump (you can save a single FX as an FX chain).

My need in this instance is to exchange recorded samples saved in indexed memory. The sender can save the current state as an FX chain. The receiver loads up the FX chain and has the option of saving it as a preset.
__________________
Mal, aka The Wasters of Time
Mal's JSFX: ReaRack2 Modular Synth

Last edited by Time Waster; 06-11-2019 at 07:41 PM.
Time Waster is offline   Reply With Quote
Old 06-11-2019, 09:48 PM   #24
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,686
Default

Quote:
Originally Posted by Time Waster View Post
The sender can save the current state as an FX chain. The receiver loads up the FX chain and has the option of saving it as a preset.
This is done by the @serialize feature. Correct ?

-Michael
mschnell is offline   Reply With Quote
Old 06-11-2019, 10:05 PM   #25
Time Waster
Human being with feelings
 
Time Waster's Avatar
 
Join Date: Aug 2013
Location: Bowral, Australia
Posts: 1,638
Default

You can save the current state in @serialize using file_mem(), but there is no convenient way that I know of to access it. It is stored in the project file, so you would need to share the whole project.
__________________
Mal, aka The Wasters of Time
Mal's JSFX: ReaRack2 Modular Synth
Time Waster is offline   Reply With Quote
Old 06-12-2019, 01:31 PM   #26
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

You can use gmem to transport the data to e.g. ReaScript. In Lua, you can reread it again and store it into a file.
This isn't convenient but should work.

Only problem to solve: gmem can hold only numbers, not strings, so you need to convert string2numbers2string, if you need them.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine 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 04:56 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.