Skip to content

Commit

Permalink
Add -ct option in faust2sndfile. Set version to 2.32.13.
Browse files Browse the repository at this point in the history
  • Loading branch information
sletz committed May 22, 2021
1 parent 72dcbc1 commit 2379be9
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 51 deletions.
2 changes: 1 addition & 1 deletion COPYING.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FAUST compiler, Version 2.32.12
FAUST compiler, Version 2.32.13
Copyright (C) 2003-2019 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version := 2.32.12
version := 2.32.13

system ?= $(shell uname -s)

Expand Down
183 changes: 183 additions & 0 deletions architecture/faust/gui/ControlSequenceUI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/************************** BEGIN ControlSequenceUI.h *******************/
/************************************************************************
FAUST Architecture File
Copyright (C) 2021 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; If not, see <http://www.gnu.org/licenses/>.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************/

#ifndef CONTROL_SEQUENCE_UI_H
#define CONTROL_SEQUENCE_UI_H

#include <vector>
#include <sstream>
#include <fstream>
#include <assert.h>

#include "faust/gui/MapUI.h"

struct TSMessage {
uint64_t fDateSample;
std::string fPath;
FAUSTFLOAT fValue;

TSMessage(uint64_t ds, const std::string& path, FAUSTFLOAT value)
:fDateSample(ds), fPath(path), fValue(value)
{}
};

/*
Allows to process a sequence of time-stamped controller messages.
*/
class ControlSequenceUI : public MapUI {

protected:

std::vector<TSMessage> fSequence;
uint64_t fDateSample;
int fEvent;

void processMessage(const TSMessage& message)
{
setParamValue(message.fPath, message.fValue);
}

public:

ControlSequenceUI(const std::vector<TSMessage>& sequence):fSequence(sequence), fDateSample(0), fEvent(0) {}
virtual ~ControlSequenceUI() {}

void process(uint64_t begin, uint64_t end)
{
if (fSequence.size() == 0) return;

// Init if needed
if (begin < fDateSample) {
fDateSample = 0;
fEvent = 0;
}

// Move until start of range
while (fSequence[fEvent].fDateSample < begin && fEvent < fSequence.size()) fEvent++;

// Process all messages in [begin, end] range
while (fEvent < fSequence.size() && fSequence[fEvent].fDateSample <= end) {
processMessage(fSequence[fEvent]);
fEvent++;
}

// Keep last date
fDateSample = fSequence[fEvent].fDateSample;
}

void display()
{
for (const auto& it : fSequence) {
std::cout << "fDateSample " << it.fDateSample << " fPath " << it.fPath << " fValue " << it.fValue << std::endl;
}
}

void getRange(uint64_t& begin, uint64_t& end)
{
if (fSequence.size() > 0) {
begin = fSequence[0].fDateSample;
end = fSequence[fSequence.size()-1].fDateSample;
} else {
begin = end = 0;
}
}

};

/*
Read a sequence of messages of type:
e45377aa.206162f1 /karplus/gate f 1.000000
e45377aa.360afa2e /karplus/gate f 0.000000
e45377ab.0a40639d /karplus/params/freq f 267.850006
e45377ab.1f47f993 /karplus/params/freq f 286.850006
e45377ab.29c88616 /karplus/params/freq f 296.350006
e45377ab.34370cdc /karplus/params/freq f 305.850006
*/

struct OSCSequenceReader {

static uint64_t readDate(const std::string& date, int sample_rate)
{
std::stringstream tokenizer(date);

std::string date1, date2;
getline(tokenizer, date1, '.');
getline(tokenizer, date2, '.');

std::istringstream date1_reader("0x" + date1);
std::istringstream date2_reader("0x" + date2);
uint32_t sec, frac;
date1_reader >> std::hex >> sec;
date2_reader >> std::hex >> frac;

double res = double(sec) + (double(frac)/std::pow(2,32));
return uint64_t(res * sample_rate);
}

static std::vector<TSMessage> read(const std::string& pathname, int sample_rate)
{
std::vector<TSMessage> res;
std::ifstream in_file(pathname);
bool first_date = true;
uint64_t first_date_sample;

if (in_file.is_open()) {
std::string line;
while (getline(in_file, line)) {
std::istringstream line_reader(line);
std::string date, path, type;
uint32_t sec, frac;

line_reader >> date;
line_reader >> path;
line_reader >> type;

// Read date, relative to first one
uint64_t date_sample = readDate(date, sample_rate);
if (first_date) {
first_date_sample = date_sample;
first_date = false;
}
date_sample -= first_date_sample;

if (type == "i") {
int value_int;
line_reader >> value_int;
res.push_back(TSMessage(date_sample, path, FAUSTFLOAT(value_int)));
} else if (type == "f") {
FAUSTFLOAT value_float;
line_reader >> value_float;
res.push_back(TSMessage(date_sample, path, value_float));
}
}
in_file.close();
}

return res;
}
};

#endif
/************************** END ControlSequenceUI.h **************************/
16 changes: 2 additions & 14 deletions architecture/faust/gui/ControlUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,28 @@
#include <vector>
#include <assert.h>

#include "faust/gui/UI.h"
#include "faust/gui/DecoratorUI.h"

class ControlUI : public UI {
class ControlUI : public DecoratorUI {

protected:

std::vector<FAUSTFLOAT*> fControlIn;
std::vector<FAUSTFLOAT*> fControlOut;

// -- widget's layouts

void openTabBox(const char* label) {}
void openHorizontalBox(const char* label) {}
void openVerticalBox(const char* label) {};
void closeBox() {}

// -- active widgets

void addButton(const char* label, FAUSTFLOAT* zone) { fControlIn.push_back(zone); }
void addCheckButton(const char* label, FAUSTFLOAT* zone) { fControlIn.push_back(zone); }
void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) { fControlIn.push_back(zone); };
void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) { fControlIn.push_back(zone); };

void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) { fControlIn.push_back(zone); };

// -- passive widgets

void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) { fControlOut.push_back(zone); };
void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) { fControlOut.push_back(zone); };

// -- soundfiles

virtual void addSoundfile(const char* label, const char* filename, Soundfile** sf_zone) {}

public:

ControlUI() {}
Expand Down
57 changes: 42 additions & 15 deletions architecture/sndfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "faust/dsp/dsp.h"
#include "faust/gui/console.h"
#include "faust/gui/FUI.h"
#include "faust/gui/ControlSequenceUI.h"
#include "faust/dsp/dsp-tools.h"
#include "faust/misc.h"

Expand Down Expand Up @@ -106,16 +107,28 @@ mydsp DSP;
std::list<GUI*> GUI::fGuiList;
ztimedmap GUI::gTimedZoneMap;

#define kFrames 512
#define kFrames 64
#define kSampleRate 44100

int main(int argc, char* argv[])
int main(int argc_aux, char* argv_aux[])
{
char name[256];
char rcfilename[256];
char* home = getenv("HOME");
snprintf(name, 256, "%s", basename(argv[0]));
snprintf(name, 256, "%s", basename(argv_aux[0]));
snprintf(rcfilename, 256, "%s/.%src", home, name);
string cfilename;

int argc = 0;
char* argv[64];
for (int i = 0; i < argc_aux; i++) {
if (string(argv_aux[i]) == "-ct") {
cfilename = argv_aux[i+1];
i++;
continue;
}
argv[argc++] = argv_aux[i];
}

// Recall state before handling commands
FUI finterface;
Expand All @@ -127,7 +140,7 @@ int main(int argc, char* argv[])
interface->process_command(FILE_MODE);
interface->printhelp_command(FILE_MODE);

bool is_rc = loptrm(&argc, argv, "-rc", "-rc", 0);
bool is_rc = loptrm(&argc, argv, "--rcfile", "-rc", 0);

if (FILE_MODE == INPUT_OUTPUT_FILE) {

Expand All @@ -152,6 +165,9 @@ int main(int argc, char* argv[])
exit(1);
}

ControlSequenceUI sequenceUI(OSCSequenceReader::read(cfilename, in_info.samplerate));
DSP.buildUserInterface(&sequenceUI);

// Init DSP with SR
DSP.init(in_info.samplerate);

Expand All @@ -169,10 +185,17 @@ int main(int argc, char* argv[])

// Process all samples
int nbf;
uint64_t cur_frame = 0;
do {
// Read samples
nbf = READ_SAMPLE(in_sf, dilv.input(), kFrames);
dilv.deinterleave();
// Update controllers
sequenceUI.process(cur_frame, cur_frame + nbf);
cur_frame += nbf;
// Compute DSP
DSP.compute(nbf, dilv.outputs(), ilv.inputs());
// Write samples
ilv.interleave();
WRITE_SAMPLE(out_sf, ilv.output(), nbf);
} while (nbf == kFrames);
Expand All @@ -198,8 +221,14 @@ int main(int argc, char* argv[])

} else {

int num_samples = loptrm(&argc, argv, "--samples", "-s", kSampleRate * 5);
int sample_rate = loptrm(&argc, argv, "--sample-rate", "-sr", kSampleRate);

ControlSequenceUI sequenceUI(OSCSequenceReader::read(cfilename, sample_rate));
uint64_t begin, end;
sequenceUI.getRange(begin, end);
DSP.buildUserInterface(&sequenceUI);

int num_samples = loptrm(&argc, argv, "--samples", "-s", ((end > 0) ? (end + kSampleRate) : kSampleRate * 5));
int bit_depth = loptrm(&argc, argv, "--bith-depth (16|24|32)", "-bd", 16);
int bd = (bit_depth == 16) ? SF_FORMAT_PCM_16 : ((bit_depth == 24) ? SF_FORMAT_PCM_24 : SF_FORMAT_PCM_32);

Expand All @@ -226,20 +255,18 @@ int main(int argc, char* argv[])
Interleaver ilv(kFrames, DSP.getNumOutputs(), DSP.getNumOutputs());

// Process all samples
int frames = num_samples;
int nbf = 0;
uint64_t cur_frame = 0;
do {
if (frames > kFrames) {
nbf = kFrames;
frames -= kFrames;
} else {
nbf = frames;
frames = 0;
}
int nbf = std::min(int(num_samples - cur_frame), int(kFrames));
// Update controllers
sequenceUI.process(cur_frame, cur_frame + nbf);
// Compute DSP
DSP.compute(nbf, nullptr, ilv.inputs());
// Write samples
ilv.interleave();
WRITE_SAMPLE(out_sf, ilv.output(), nbf);
} while (nbf);
cur_frame += nbf;
} while (cur_frame < num_samples);

sf_close(out_sf);

Expand Down
2 changes: 1 addition & 1 deletion build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project (faust)

#######################################
# versions management
set (VERSION 2.32.12)
set (VERSION 2.32.13)
macro (get_major_minor_patch version)
string( REGEX REPLACE "([0-9]*)\\.([0-9]*)\\.([0-9]*)" "\\1" VERSION_MAJOR ${version} )
string( REGEX REPLACE "([0-9]*)\\.([0-9]*)\\.([0-9]*)" "\\2" VERSION_MINOR ${version} )
Expand Down
2 changes: 1 addition & 1 deletion build/MakeRelease.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ echo off
IF [%1]==[] GOTO USAGE
IF NOT EXIST %1 GOTO USAGE

SET VERSION=2.32.12
SET VERSION=2.32.13
SET BUILD=%1
SET FAUSTGENVERSION=1.48
SET FAUSTLIVE=../../faustlive
Expand Down
2 changes: 1 addition & 1 deletion build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ system := $(shell echo $(system) | grep MINGW > /dev/null && echo MINGW || echo
# output directories
FAUSTDIR ?= faustdir
IOSDIR := iosdir
VERSION := 2.32.12
VERSION := 2.32.13

#===============================================================
# current generator and backends
Expand Down
2 changes: 1 addition & 1 deletion compiler/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% man(1) Version 2.32.12 (16-May-2021) | Faust man page
% man(1) Version 2.32.13 (22-May-2021) | Faust man page

NAME
====
Expand Down
Loading

0 comments on commit 2379be9

Please sign in to comment.