ちなみに、公式TutorialではJUCEでは全てのAudioParameterは[0, 1]のレンジで保存される、とあります。JUCE stores all of the parameter values in the range [0, 1] as this is a limitation of some of the target plug-in APIs.
void ChordGeniusAudioProcessor::getStateInformation(juce::MemoryBlock& destData) {
// copying State from apvts, then create XML from it.
if (auto xmlState = valueTreeState.copyState().createXml())
{
// dereference from xmlState and copying it to MemoryBlock
// human readable xml will allow debugging...
copyXmlToBinary(*xmlState, destData);
}
}
プロジェクトをloadする時、Hostが setStateInformation (const void* data, int sizeInByte)をコールしします。
void ChordGeniusAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
if(auto xmlState = getXmlFromBinary (data, sizeInBytes)
{
if (xmlState->hasTagName(valueTreeState.state.getType())) {
const auto newTree = juce::ValueTree::fromXml(*xmlState);
valueTreeState.replaceState(newTree);
}
}
}
APVTSからパラメータをゲットする時は
// returns juce::Value type object
auto param = valueTreeState.getParameterAsValue("PARAMETER_ID");
パラメータに値をセットするときは
// need to cast to juce::var type in order for Host application to save and persist the plut-in state.
param.setValue(juce::var(newValue));
// PlaySound.swift
class PlaySound {
private var meter: Int = 4
public func printMeter() {
print(meter)
}
public func getMeter() -> Int {
return meter
}
}
int a = 5;
int* ptr = &a;
std::cout << *a << std::endl; // prints 5 (value of a)
int& ref = a; // ref is now an alias of a
ref = 2;
std::cout << a << std::endl; // prints 2
class Entity {
public:
// a constructor without parameter
Entity {
}
// a constructor with initializer lists
Entity(float x, float y)
: X(x), Y(y) // it needs to be in the same order as you declared
{
}
// a constructor with parameters
Entity(float x, float y) {
X = x;
Y = y;
}
float X, Y;
}
class Log {
public:
// by assigning delete, can disable default constructor
Log() = delete;
}
const int MAX_AGE = 90;
int* a = new int; // a is a pointer
*a = 2; // you can dereference a and assign 2
a = (int*)&MAX_AGE // you can reassign pointer
const int* a = new int; // add "const" keyword to a pointer
// you can also write it as "int const* a"
*a = 2; // error, you can't modify the contents of the pointer
a = (int*)&MAX_AGE; // no error
std::cout << *a << std::endl; // reading a works
int* const a = new int;
*a = 2; // this works
a = (int*)&MAX_AGE; // error
a = nullptr; // error
class Entity {
private:
int m_X, m_Y;
public:
int GetX() const { // it means the function can't modify the value
// read only method
// good for getters
m_X = 2; // can't do this
return m_X;
}
void SetX(int x) { // can't have const here...
m_X = x;
}
}
void PrintEntity(const Entity& e) {
std::cout << e.GetX() << std::end; // if I remove const from
// the above GetX(), it won't work
}
int i = 5;
int& a = 10; // this does not work, because 10 is a rvalue
int& b = i; // this works, because i is a lvalue
const int& c = 10; // this works
// it creates a temporary behind the scenes as in the below pseudo code
int temp = 10;
int& c = temp;
// Main.cpp
#include "MainComponent.h"
// MainWindow constructor
MainWindow(juce::String name): DocumentWindow(name,
juce::Colours::lightgrey,
DocumentWindow::allButtons)
{
setUsingNativeTitleBar(true);
// assigning MainComponent instance in setContentOwned()
setContentOwned(new MainComponent(), true);
// [6 ] in order for getWidth() and getHeight() to work,
// MainComponent needs to have setSize() set in it's constructor
centreWithSize(getWidth(), getHeight());
setVisible(true);
}
paint(juce::Graphics& g) にはGraphicsクラスのインスタンスのアドレス g が渡されています。この g を使って色々なUIエレメントを描画出来ます。ほぼ全ての場合、Graphicsクラスはpaint()内でのみ使用されます。
Fontの設定
g.setFont(20.0f); // set size of the font
juce::Font mainComponentFont ("Times New Roman", 20.0f, juce::Font::italic);
// font styles can be used as a bitmask
juce::Font mainComponentFont ("Times New Roman", 20.0f, juce::Font::bold | juce::Font::italic);
g.setFont(mainComponentFont); // can pass a Font object
// using getLocalBounds()
g.drawText(currentSizeAsString, getLocalBounds(), juce::Justification::centred, true);
// using Justification::Flags
g.drawText(currentSizeAsString, getLocalBounds(), juce::Justification::topLeft, true);
// using explicit size and position
g.drawText(currentSizeAsString, 20, 40, 200, 40, juce::Justification::centred, true);
// draws a line with 5 pixels width from (10, 300) to (590, 300),
g.drawLine (10, 300, 590, 300, 5);
// draws a rectangle with origin (300, 120), width 200, height 170
g.drawRect (300, 120, 200, 170);
// draws a ellipse inside a rectangle with origin (530, 120), width and height 60 pixels
g.drawEllipse (530, 120, 60, 60, 3);
git clone https://github.com/juce-framework/JUCE.git JUCE_dev
cd ./JUCE_dev
git checkout develop
// branch 'develop' set up to track 'origin/develop'.
// Switched to a new branch 'develop'