sequencer
note.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <sequencer/assert.hpp>
4 
5 #include <cassert>
6 #include <cstdint>
7 #include <limits>
8 
9 namespace sequencer::midi
10 {
11  enum class note_t : std::uint8_t
12  {
13  no_note = std::numeric_limits< std::uint8_t >::max()
14  };
15 
16  constexpr note_t no_note() noexcept
17  {
18  return note_t::no_note;
19  }
20 
21  constexpr std::uint8_t to_uint8_t( note_t note ) noexcept
22  {
23  return static_cast< std::uint8_t >( note );
24  }
25 
26  constexpr note_t operator+( note_t note, std::int16_t offset )
27  {
28  SEQUENCER_ASSERT( to_uint8_t( note ) + offset < 128 )
29  return note_t{std::uint8_t( to_uint8_t( note ) + offset )};
30  }
31 
32  constexpr std::int16_t get_note_distance( note_t lhs, note_t rhs ) noexcept
33  {
34  return to_uint8_t( rhs ) - to_uint8_t( lhs );
35  }
36 } // namespace sequencer::midi
constexpr std::int16_t get_note_distance(note_t lhs, note_t rhs) noexcept
Definition: note.hpp:32
constexpr note_t operator+(note_t note, std::int16_t offset)
Definition: note.hpp:26
note_t
Definition: note.hpp:11
#define SEQUENCER_ASSERT(cond)
Definition: assert.hpp:8
constexpr std::uint8_t to_uint8_t(note_t note) noexcept
Definition: note.hpp:21
Definition: clock.hpp:13