Permalink
Browse files

MIDI::SystemRealTimeMessage

  • Loading branch information...
mlang committed Jul 26, 2017
1 parent 514c7ec commit 28ecae031dff3cf7c46fdc2390edd2a5d024118b
Showing with 43 additions and 7 deletions.
  1. +2 −4 edge.cpp
  2. +1 −1 lib/CMakeLists.txt
  3. +1 −1 lib/jack.cpp
  4. +22 −1 lib/jack.hpp
  5. +17 −0 lib/midi.hpp
View
@@ -18,9 +18,7 @@ class EdgeDetect : public JACK::Client {
, MIDIOut(createMIDIOut("Out"))
, FastAverage(0.25), SlowAverage(0.0625)
, Threshold(Threshold)
{
Expects(Threshold > 0);
}
{ Expects(Threshold > 0); }
int process(std::uint32_t FrameCount) override {
auto MIDIBuffer = MIDIOut.buffer(FrameCount);
@@ -31,7 +29,7 @@ class EdgeDetect : public JACK::Client {
auto Difference = FastAverage(Sample) - SlowAverage(Sample);
if (PreviousDifference < Threshold && Difference > Threshold) {
MIDIBuffer.reserve<1>(Frame)[0] = gsl::byte(0XFB);
MIDIBuffer[Frame] = MIDI::SystemRealTimeMessage::Clock;
std::cout << "Positive Edge (" << Frame << ", " << FramesPerPulse << ")" << "\n";
FramesPerPulse = 0;
}
View
@@ -3,4 +3,4 @@ find_package(JACK REQUIRED)
add_subdirectory(GSL)
add_library(IO brlapi.cpp jack.cpp)
target_link_libraries(IO PUBLIC GSL PRIVATE JACK BrlAPI)
target_include_directories(IO INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(IO PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
View
@@ -149,7 +149,7 @@ MIDIOut::MIDIOut(JACK::Client *Client, std::string Name)
{}
MIDIBuffer MIDIOut::buffer(std::int32_t FrameCount) {
return MIDIBuffer(jack_port_get_buffer(JACK->Port, FrameCount));
return { jack_port_get_buffer(JACK->Port, FrameCount), FrameCount };
}
extern "C" int process(jack_nframes_t nframes, void *instance)
View
@@ -6,6 +6,8 @@
#include <gsl/gsl>
#include <midi.hpp>
namespace JACK {
class Client;
@@ -46,19 +48,38 @@ class AudioOut : public Port {
class MIDIBuffer {
void *Buffer;
std::uint32_t const Frames;
friend class MIDIOut;
explicit MIDIBuffer(void *Buffer) : Buffer(Buffer) {
MIDIBuffer(void *Buffer, std::uint32_t FrameCount) : Buffer(Buffer), Frames(FrameCount) {
Expects(Buffer != nullptr);
}
public:
class Index {
MIDIBuffer &Buffer;
std::uint32_t Offset;
friend class MIDIBuffer;
Index(MIDIBuffer &Buffer, std::uint32_t Offset)
: Buffer(Buffer), Offset(Offset) {}
public:
Index &operator=(MIDI::SystemRealTimeMessage Message) {
Buffer.reserve<1>(Offset)[0] = static_cast<gsl::byte>(Message);
return *this;
}
};
void clear();
gsl::span<gsl::byte> reserve(std::uint32_t FrameOffset, std::uint32_t Size);
template<std::uint32_t Size>
gsl::span<gsl::byte, Size> reserve(std::uint32_t FrameOffset) {
return reserve(FrameOffset, Size);
}
Index operator[](std::uint32_t FrameOffset) {
Ensures(FrameOffset < Frames);
return { *this, FrameOffset };
}
};
class MIDIOut : public Port {
View
@@ -0,0 +1,17 @@
#if !defined(BrlCV_MIDI_HPP)
#define BrlCV_MIDI_HPP
namespace MIDI {
enum class SystemRealTimeMessage {
Clock = 0b11111000,
Start = 0b11111010,
Continue = 0b11111011,
Stop = 0b11111100,
ActiveSensing = 0b11111110,
Reset = 0b11111111
};
}
#endif // BrlCV_MIDI_HPP

0 comments on commit 28ecae0

Please sign in to comment.