mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Bela: Support for analog inputs
This commit is contained in:
parent
c80285463a
commit
fab1442ceb
1 changed files with 48 additions and 1 deletions
|
|
@ -89,6 +89,11 @@ public:
|
|||
return devices;
|
||||
}
|
||||
|
||||
void pushMidiMessage (juce::MidiMessage& message)
|
||||
{
|
||||
concatenator.pushMidiData (message.getRawData(), message.getRawDataSize(), Time::getMillisecondCounter() * 0.001, midiInput, *midiCallback);
|
||||
}
|
||||
|
||||
private:
|
||||
void pushMidiData (int length)
|
||||
{
|
||||
|
|
@ -182,6 +187,9 @@ public:
|
|||
BelaAudioIODevice::belaTypeName)
|
||||
{
|
||||
Bela_defaultSettings (&defaultSettings);
|
||||
|
||||
if (includeAnalogSupport)
|
||||
analogInputs.resize (8);
|
||||
}
|
||||
|
||||
~BelaAudioIODevice()
|
||||
|
|
@ -213,7 +221,7 @@ public:
|
|||
auto numIns = getNumContiguousSetBits (inputChannels);
|
||||
auto numOuts = getNumContiguousSetBits (outputChannels);
|
||||
|
||||
settings.useAnalog = 0;
|
||||
settings.useAnalog = includeAnalogSupport ? 1 : 0;
|
||||
settings.useDigital = 0;
|
||||
settings.numAudioInChannels = numIns;
|
||||
settings.numAudioOutChannels = numOuts;
|
||||
|
|
@ -353,6 +361,7 @@ public:
|
|||
static const char* const belaTypeName;
|
||||
|
||||
private:
|
||||
|
||||
//==============================================================================
|
||||
bool setup (BelaContext& context)
|
||||
{
|
||||
|
|
@ -377,6 +386,9 @@ private:
|
|||
|
||||
ScopedLock lock (callbackLock);
|
||||
|
||||
if (includeAnalogSupport)
|
||||
updateAnalogInputs (context);
|
||||
|
||||
// Check for and process and midi
|
||||
for (auto midiInput : BelaMidiInput::midiInputs)
|
||||
midiInput->poll();
|
||||
|
|
@ -448,6 +460,39 @@ private:
|
|||
callback->audioDeviceStopped();
|
||||
}
|
||||
|
||||
void updateAnalogInputs (BelaContext& context)
|
||||
{
|
||||
for (size_t i = 0; i < 8; i++)
|
||||
{
|
||||
auto v = analogRead (&context, 0, static_cast<int> (i));
|
||||
|
||||
if (fabs (analogInputs[i].previousInput - v) > 1.0f/512.0f)
|
||||
{
|
||||
auto controlValue = int (v * 127.0);
|
||||
|
||||
if (analogInputs[i].previousControlValue != controlValue)
|
||||
{
|
||||
// Consider this to have moved
|
||||
analogInputs[i].previousInput = v;
|
||||
analogInputs[i].previousControlValue = controlValue;
|
||||
|
||||
auto message = MidiMessage::controllerEvent (1, 16 + i, controlValue);
|
||||
|
||||
for (auto midiInput : BelaMidiInput::midiInputs)
|
||||
midiInput->pushMidiMessage (message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct AnalogInput
|
||||
{
|
||||
float previousInput = 0;
|
||||
int previousControlValue = 0;
|
||||
};
|
||||
|
||||
std::vector<AnalogInput> analogInputs;
|
||||
|
||||
|
||||
//==============================================================================
|
||||
uint64_t expectedElapsedAudioSamples = 0;
|
||||
|
|
@ -494,6 +539,8 @@ private:
|
|||
HeapBlock<const float*> channelInBuffer;
|
||||
HeapBlock<float*> channelOutBuffer;
|
||||
|
||||
bool includeAnalogSupport = true;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BelaAudioIODevice)
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue