Skip to content

Commit

Permalink
- update internal test project
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Hart committed May 28, 2023
1 parent 4742496 commit 1f2e8a7
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 11 deletions.
36 changes: 28 additions & 8 deletions loris_test/Source/MainComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using namespace juce;



//==============================================================================
MainComponent::MainComponent():
fc("File", File(), true, false, false, "*", "", "Select audio file to analyse"),
Expand Down Expand Up @@ -160,7 +162,16 @@ MainComponent::MainComponent():
repaint();
};

setSize (600, 400);
File audioFile("/Users/christophhart/Development/loris-tools/Loris Toolbox/AudioFiles/sound_examples/piano 2.wav");

for(int i = 0; i < 8; i++)
{
pathColours[i] = Colours::red.withSaturation(0.7f).withBrightness(0.4f).withAlpha(0.3f).withHue(Random::getSystemRandom().nextFloat());
}

setSize (900, 600);

fc.setCurrentFile(audioFile, true);
}

MainComponent::~MainComponent()
Expand All @@ -170,13 +181,17 @@ MainComponent::~MainComponent()
//==============================================================================
void MainComponent::paint (juce::Graphics& g)
{
// (Our component is opaque, so we must completely fill the background with a solid colour)
g.fillAll(Colour(0xff222222));

}

g.setFont (GLOBAL_FONT());
g.setColour (juce::Colours::white);
void MainComponent::paintOverChildren(juce::Graphics& g)
{
for(int i = 0; i < harmonics.size(); i++)
{
g.setColour(Colour(pathColours[i]).withAlpha(0.15f));
g.fillPath(harmonics[i]);
}

g.drawText (error, errorArea, juce::Justification::centred, true);
}

void MainComponent::resized()
Expand All @@ -203,8 +218,13 @@ void MainComponent::resized()

thumbnail.setBounds(b.reduced(3));



if(!harmonics.isEmpty())
{
auto t = thumbnail.getBounds().toFloat();

for(auto& e: harmonics)
e.scaleToFit(t.getX(), t.getY(), t.getWidth(), t.getHeight(), false);
}


// This is called when th MainComponent is resized.
Expand Down
40 changes: 37 additions & 3 deletions loris_test/Source/MainComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,61 @@ class MainComponent : public juce::Component,

//==============================================================================
void paint (juce::Graphics&) override;

void paintOverChildren(juce::Graphics& g) override;
void resized() override;



virtual void filenameComponentChanged (FilenameComponent* fileComponentThatHasChanged) override
{
lorisManager->analyse({{fc.getCurrentFile(), 440.0}}, nullptr);
lorisManager->set("freqdrift", "50.0");

//auto freq = 146.8323839587038; // cello
auto freq = 329.6275569128699; // (piano 2);

auto bl = lorisManager->synthesise(fc.getCurrentFile());
lorisManager->analyse({{fc.getCurrentFile(), freq}}, nullptr);

auto gainList = lorisManager->getSnapshot(fc.getCurrentFile(), 0.5, "bandwidth")[0];

DBG(JSON::toString(gainList));

//auto pitchEnv = lorisManager->createEnvelope(fc.getCurrentFile(), Identifier("rootFrequency"), 0);

Identifier id("gain");

var pitchEnv;

for(int i = 0; i < 8; i++)
{
if(!pitchEnv.isBuffer())
pitchEnv = lorisManager->createEnvelope(fc.getCurrentFile(), id, i)[0];
else
*pitchEnv.getBuffer() += *lorisManager->createEnvelope(fc.getCurrentFile(), id, i)[0].getBuffer();

auto e = lorisManager->setEnvelope(pitchEnv, id);

harmonics.add(e);
}




auto bl = lorisManager->synthesise(fc.getCurrentFile());

thumbnail.setBuffer(bl[0], bl[1]);

repaint();
resized();
}



private:

Array<Path> harmonics;

Colour pathColours[8];

//==============================================================================
// Your private member variables go here...

Expand Down

0 comments on commit 1f2e8a7

Please sign in to comment.