Skip to content

Commit

Permalink
implement status listener calls in controller and monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
vsicurella committed Jan 13, 2024
1 parent ef45d80 commit 4f6cc3f
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 35 deletions.
4 changes: 4 additions & 0 deletions Source/lumatone_editor_library/data/application_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class LumatoneFirmwareDriver;
class LumatoneController;
class LumatoneColourModel;
class LumatoneAction;
class DeviceActivityMonitor;

class LumatoneApplicationState : public LumatoneState
{
Expand Down Expand Up @@ -142,6 +143,9 @@ class LumatoneApplicationState : public LumatoneState
void addFirmwareListener(LumatoneEditor::FirmwareListener* listenerIn);
void removeFirmwareListener(LumatoneEditor::FirmwareListener* listenerIn);

// Allow these to edit state and signal listeners
friend class LumatoneController;
friend class DeviceActivityMonitor;
};

#endif LUMATONE_APPLICATION_STATE_H
12 changes: 8 additions & 4 deletions Source/lumatone_editor_library/device/activity_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "../lumatone_midi_driver/lumatone_midi_driver.h"
#include "../lumatone_midi_driver/firmware_sysex.h"
#include "../listeners/status_listener.h"


DeviceActivityMonitor::DeviceActivityMonitor(LumatoneFirmwareDriver* midiDriverIn, LumatoneApplicationState stateIn)
: LumatoneApplicationState("DeviceActivityMonitor", stateIn)
Expand Down Expand Up @@ -263,7 +265,7 @@ void DeviceActivityMonitor::checkDetectionStatus()
if (isConnectionEstablished())
{
deviceDetectInProgress = false;
//statusListeners->call(&LumatoneEditor::StatusListener::connectionStateChanged, ConnectionState::ONLINE);
statusListeners->call(&LumatoneEditor::StatusListener::connectionStateChanged, ConnectionState::ONLINE);

outputPingIds.clear();

Expand All @@ -284,7 +286,7 @@ void DeviceActivityMonitor::checkDetectionStatus()
waitingForResponse = false;
startTimer(detectRoutineTimeoutMs);

//statusListeners.call(&LumatoneEditor::StatusListener::connectionFailed);
statusListeners->call(&LumatoneEditor::StatusListener::connectionFailed);
}
else
{
Expand Down Expand Up @@ -338,7 +340,7 @@ void DeviceActivityMonitor::checkDetectionStatus()
waitingForResponse = false;
startTimer(detectRoutineTimeoutMs);

//statusListeners.call(&LumatoneEditor::StatusListener::connectionFailed);
statusListeners->call(&LumatoneEditor::StatusListener::connectionFailed);
}
}

Expand Down Expand Up @@ -419,6 +421,7 @@ void DeviceActivityMonitor::handleResponse(int inputDeviceIndex, const juce::Mid

if (cmd == PERIPHERAL_CALBRATION_DATA && !isConnectionEstablished())
{
DBG("DAM: Unexpected calibration data received");
sendCalibratePitchModOff = true;
// startTimer(100);
return;
Expand Down Expand Up @@ -451,6 +454,7 @@ void DeviceActivityMonitor::handleResponse(int inputDeviceIndex, const juce::Mid
if (!isConnectionEstablished())
{
sendCalibratePitchModOff = true;
jassertfalse;
}
}
break;
Expand Down Expand Up @@ -566,7 +570,7 @@ void DeviceActivityMonitor::onDisconnection()

waitingForResponse = false;

//juce::MessageManager::callAsync([&]() { statusListeners.call(&LumatoneEditor::StatusListener::connectionStateChanged, ConnectionState::DISCONNECTED); });
statusListeners->call(&LumatoneEditor::StatusListener::connectionStateChanged, ConnectionState::DISCONNECTED);

if (detectDevicesIfDisconnected)
{
Expand Down
4 changes: 1 addition & 3 deletions Source/lumatone_editor_library/device/activity_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
#include "../lumatone_midi_driver/firmware_driver_listener.h"

#include "../data/application_state.h"
#include "../listeners/status_listener.h"

class LumatoneFirmwareDriver;

class DeviceActivityMonitor : protected LumatoneApplicationState,
public juce::Timer,
public LumatoneEditor::StatusEmitter,
public juce::Timer,
protected LumatoneFirmwareDriverListener
{

Expand Down
75 changes: 47 additions & 28 deletions Source/lumatone_editor_library/device/lumatone_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "lumatone_event_manager.h"
#include "../actions/lumatone_action.h"
#include "../lumatone_midi_driver/lumatone_midi_driver.h"
#include "../listeners/editor_listener.h"

LumatoneController::LumatoneController(const LumatoneApplicationState& stateIn, LumatoneFirmwareDriver& firmwareDriverIn, juce::UndoManager* undoManager)
: LumatoneApplicationState("LumatoneController", stateIn, undoManager)
Expand Down Expand Up @@ -641,7 +642,7 @@ void LumatoneController::onConnectionConfirmed()
sendGetFirmwareRevisionRequest();
}

//statusListeners.call(&LumatoneEditor::StatusListener::connectionStateChanged, ConnectionState::ONLINE);
statusListeners->call(&LumatoneEditor::StatusListener::connectionStateChanged, ConnectionState::ONLINE);
}

// bool LumatoneController::loadLayoutFromFile(const juce::File& file)
Expand Down Expand Up @@ -700,78 +701,96 @@ void LumatoneController::pingResponseReceived(unsigned int pingValue)

void LumatoneController::octaveColourConfigReceived(int boardId, juce::uint8 rgbFlag, const int* colourData)
{
auto octaveSize = getOctaveBoardSize();
auto numBoards = getNumBoards();
LumatoneBoard editedBoard = getBoard(boardId - 1);

int boardIndex = boardId - 1;

for (int keyIndex = 0; keyIndex < octaveSize; keyIndex++)
for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++)
{
LumatoneKey keyData = getKey(boardIndex, keyIndex);
auto newValue = colourData[keyIndex];

juce::Colour colour = editedBoard.getKey(keyIndex).getColour();
if (rgbFlag == 0)
{
keyData.setColour(juce::Colour(newValue, keyData.getColour().getGreen(), keyData.getColour().getBlue()));
colour = juce::Colour(newValue, colour.getGreen(), colour.getBlue());
}
else if (rgbFlag == 1)
{
keyData.setColour(juce::Colour(keyData.getColour().getRed(), newValue, keyData.getColour().getBlue()));
colour = juce::Colour(colour.getRed(), newValue, colour.getBlue());
}
else if (rgbFlag == 2)
{
keyData.setColour(juce::Colour(keyData.getColour().getRed(), keyData.getColour().getGreen(), newValue));
colour = juce::Colour(colour.getRed(), colour.getGreen(), newValue);
}
else
{
jassertfalse;
}

editedBoard.setKeyColour(colour, keyIndex);
}

//editorListeners.call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardIndex));
LumatoneState::setBoard(editedBoard, boardId);
editorListeners->call(&LumatoneEditor::EditorListener::boardChanged, editedBoard);
};


void LumatoneController::octaveChannelConfigReceived(int boardId, const int* channelData)
{
LumatoneBoard editedBoard = getBoard(boardId - 1);

for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++)
{
// Check channel values?
auto key = getKey(boardId-1, keyIndex);
key.setChannelNumber(channelData[keyIndex]);
LumatoneState::setKey(key, boardId, keyIndex);
// getEditKey(boardId-1, keyIndex)->channelNumber = channelData[keyIndex];
juce::uint8 ch = channelData[keyIndex];
if (ch == 0 || ch > 16)
ch = 1;

auto key = editedBoard.getKey(keyIndex);
key.setChannelNumber(ch);
editedBoard.setKeyConfig(key, keyIndex);
}

//editorListeners.call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardId - 1));
LumatoneState::setBoard(editedBoard, boardId);
editorListeners->call(&LumatoneEditor::EditorListener::boardChanged, editedBoard);
}

void LumatoneController::octaveNoteConfigReceived(int boardId, const int* noteData)
{
LumatoneBoard editedBoard = getBoard(boardId - 1);

for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++)
{
auto key = getKey(boardId-1, keyIndex);
int note = noteData[keyIndex];
if (note < 0 || note > 127)
note = 0;

auto key = editedBoard.getKey(keyIndex);
key.setNoteOrCC(noteData[keyIndex]);
LumatoneState::setKey(key, boardId, keyIndex);
// Check note values?
// getEditKey(boardId - 1, keyIndex)->noteNumber = noteData[keyIndex];
editedBoard.setKeyConfig(key, keyIndex);
}

//editorListeners.call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardId - 1));
LumatoneState::setBoard(editedBoard, boardId);
editorListeners->call(&LumatoneEditor::EditorListener::boardChanged, editedBoard);
}

void LumatoneController::keyTypeConfigReceived(int boardId, const int* keyTypeData)
{
LumatoneBoard editedBoard = getBoard(boardId - 1);

for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++)
{
auto key = getKey(boardId-1, keyIndex);
key.setKeyType((LumatoneKeyType)keyTypeData[keyIndex]);
LumatoneState::setKey(key, boardId, keyIndex);
// Check note values?
// getEditKey(boardId - 1, keyIndex)->keyType = LumatoneKeyType(keyTypeData[keyIndex]);
auto type = LumatoneKeyType(keyTypeData[keyIndex]);

auto key = editedBoard.getKey(keyIndex);
key.setKeyType(type);
editedBoard.setKeyConfig(key, keyIndex);
}

//editorListeners.call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardId - 1));
LumatoneState::setBoard(editedBoard, boardId);
editorListeners->call(&LumatoneEditor::EditorListener::boardChanged, editedBoard);
}

void LumatoneController::macroButtonColoursReceived(juce::Colour inactiveColour, juce::Colour activeColour)
{

}

//void LumatoneController::loadRandomMapping(int testTimeoutMs, int maxIterations, int i)
Expand Down
2 changes: 2 additions & 0 deletions Source/lumatone_editor_library/device/lumatone_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ class LumatoneController : private LumatoneApplicationState
void octaveNoteConfigReceived(int octaveIndex, const int* noteData) override;
void keyTypeConfigReceived(int boardId, const int* keyTypeData) override;

void macroButtonColoursReceived(juce::Colour inactiveColour, juce::Colour activeColour) override;

//============================================================================
// Test functions

Expand Down

0 comments on commit 4f6cc3f

Please sign in to comment.