-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Midi display #96
base: main
Are you sure you want to change the base?
Midi display #96
Changes from all commits
8947290
a848a0b
022f34a
a4cbe28
7850510
de0e44d
6cbd145
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,10 +59,11 @@ void MidiParameterMapper::processMidiBuffer (juce::MidiBuffer& buffer) | |
|
||
for (auto m : buffer) | ||
{ | ||
if (m.getMessage().isController()) | ||
juce::MidiMessage mm = m.getMessage(); | ||
if (mm.isController()) | ||
{ | ||
auto number = m.getMessage().getControllerNumber(); | ||
auto value = m.getMessage().getControllerValue() / 127.0f; | ||
auto number = mm.getControllerNumber(); | ||
auto value = mm.getControllerValue() / 127.0f; | ||
lastController.store (number); | ||
|
||
if (isLocked) | ||
|
@@ -78,6 +79,11 @@ void MidiParameterMapper::processMidiBuffer (juce::MidiBuffer& buffer) | |
p->endChangeGesture(); | ||
} | ||
} | ||
} else if (mm.isNoteOn()) | ||
{ | ||
lastMidiChannel.store(mm.getChannel()); | ||
lastMidiNote.store(mm.getNoteNumber()); | ||
lastMidiVelocity.store(mm.getVelocity()); | ||
} | ||
} | ||
|
||
|
@@ -90,6 +96,20 @@ void MidiParameterMapper::mapMidiController (int cc, const juce::String& paramet | |
auto mappings = getMappingSettings(); | ||
|
||
juce::ValueTree node { IDs::mapping, {{IDs::cc, cc}, {IDs::parameter, parameterID}} }; | ||
|
||
// If mapping already there, remove it: | ||
if (mappings.isValid()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for my OCD, but please let's stay with 4 spaces ;-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do try to keep to four spaces in your code, but sometimes I slip, because both Emacs and Xcode are set to two spaces for me. Yes, clang-format is a good answer! |
||
int index = 0; | ||
while (index < mappings.getNumChildren()) { | ||
const auto& child = mappings.getChild (index); | ||
if (int (child.getProperty (IDs::cc, -1)) == cc && child.getProperty (IDs::parameter, juce::String()).toString() == parameterID) { | ||
mappings.removeChild (child, nullptr); | ||
return; | ||
} else | ||
++index; | ||
} | ||
} | ||
// Otherwise add it: | ||
mappings.appendChild (node, nullptr); | ||
} | ||
|
||
|
@@ -132,6 +152,21 @@ int MidiParameterMapper::getLastController() const | |
return lastController.load(); | ||
} | ||
|
||
int MidiParameterMapper::getLastMidiChannel() const | ||
{ | ||
return lastMidiChannel.load(); | ||
} | ||
|
||
int MidiParameterMapper::getLastMidiNote() const | ||
{ | ||
return lastMidiNote.load(); | ||
} | ||
|
||
int MidiParameterMapper::getLastMidiVelocity() const | ||
{ | ||
return lastMidiVelocity.load(); | ||
} | ||
|
||
juce::ValueTree MidiParameterMapper::getMappingSettings() | ||
{ | ||
return settings->settings.getOrCreateChildWithName (IDs::mappings, nullptr); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
============================================================================== | ||
Copyright (c) 2023 Julius Smith and Foleys Finest Audio - Daniel Walz | ||
All rights reserved. | ||
|
||
**BSD 3-Clause License** | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
3. Neither the name of the copyright holder nor the names of its contributors | ||
may be used to endorse or promote products derived from this software without | ||
specific prior written permission. | ||
|
||
============================================================================== | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
OF THE POSSIBILITY OF SUCH DAMAGE. | ||
============================================================================== | ||
*/ | ||
|
||
#include "foleys_MidiDisplayComponent.h" | ||
|
||
namespace foleys | ||
{ | ||
|
||
void MidiDisplayComponent::setMagicProcessorState (MagicProcessorState* state) | ||
{ | ||
processorState = state; | ||
startTimerHz (4); | ||
} | ||
|
||
void MidiDisplayComponent::paint (juce::Graphics& g) | ||
{ | ||
if (processorState) | ||
{ | ||
auto channel = processorState->getLastMidiChannel(); | ||
auto text = juce::String("Channel: " + (channel > 0 ? juce::String (channel) : "unknown")); | ||
|
||
auto note = processorState->getLastMidiNote(); | ||
text += ("\nNote: " + (note > 0 ? juce::String (note) : "unknown")); | ||
|
||
auto velocity = processorState->getLastMidiVelocity(); | ||
text += ("\nVelocity: " + (velocity > 0 ? juce::String (velocity) : "unknown")); | ||
|
||
auto cc = processorState->getLastController(); | ||
text += ("\nCC: " + (cc > 0 ? juce::String (cc) : "unknown")); | ||
|
||
g.setColour (juce::Colours::silver); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to have those configurable... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the GuiItem should take care of that. Colo[u]r is something I've never spent any time on, but I'm sure it's easy to learn. Also, font size and spacing et al. should be configurable in the GuiItem, maybe even the layout as well. It's hard to know where to stop on this stuff. What would be really cool would be a pop-up text-editor, analogous to the color inspector, that allows super general control like any good rich text editor. Then properties would have magic names like "$lastControllerColour" that would do the right thing, analogous to spreadsheet cell references. For the short term, I'll take a look at what MIDI Learn offers and at least get it to that level. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idea: The MidiDisplayComponent should only display one item, and a pop-up list can support selecting which one. That way, each item can be dragged into a View and arranged via flexbox or in "contents mode" in the normal way. |
||
g.drawFittedText (text, getLocalBounds(), juce::Justification::centred, 1); | ||
} | ||
} | ||
|
||
void MidiDisplayComponent::mouseDrag (const juce::MouseEvent& event) | ||
{ | ||
if (processorState && event.mouseWasDraggedSinceMouseDown()) | ||
{ | ||
auto cc = processorState->getLastController(); | ||
if (cc < 1) | ||
return; | ||
|
||
if (auto* container = juce::DragAndDropContainer::findParentDragContainerFor (this)) | ||
{ | ||
container->startDragging (IDs::dragCC + juce::String (cc), this); | ||
} | ||
} | ||
} | ||
|
||
void MidiDisplayComponent::timerCallback() | ||
{ | ||
repaint(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
============================================================================== | ||
Copyright (c) 2023 Julius Smith and Foleys Finest Audio - Daniel Walz | ||
All rights reserved. | ||
|
||
**BSD 3-Clause License** | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
3. Neither the name of the copyright holder nor the names of its contributors | ||
may be used to endorse or promote products derived from this software without | ||
specific prior written permission. | ||
|
||
============================================================================== | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
OF THE POSSIBILITY OF SUCH DAMAGE. | ||
============================================================================== | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <juce_gui_basics/juce_gui_basics.h> | ||
|
||
namespace foleys | ||
{ | ||
|
||
class MagicProcessorState; | ||
|
||
/** | ||
The MidiDisplayComponent displays the last moved CC controller and allows via dragging | ||
onto a knob to connect to its parameter | ||
*/ | ||
class MidiDisplayComponent : public juce::Component, | ||
public juce::SettableTooltipClient, | ||
private juce::Timer | ||
{ | ||
public: | ||
MidiDisplayComponent() = default; | ||
|
||
void setMagicProcessorState (MagicProcessorState* state); | ||
|
||
void paint (juce::Graphics& g) override; | ||
void mouseDrag (const juce::MouseEvent& event) override; | ||
|
||
private: | ||
|
||
void timerCallback() override; | ||
|
||
MagicProcessorState* processorState = nullptr; | ||
|
||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiDisplayComponent) | ||
}; | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about exposing the midiMapper instead of cluttering the MagicProcessorState API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds fine to me - I was just following the pattern I found in front of me, really shooting for "minimum perturbation".