resonance 1.0.1
Loading...
Searching...
No Matches
notefinder.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <vector>
5
6#include "app/msgsink.h"
7#include "mid/tick.h"
8#include "mid/tickobj.h"
9#include "msg/musemsg.h"
10#include "msg/notemsg.h"
11
12class Message;
13
22class NoteFinder : public MsgSink {
23public:
26 }
27
38 void Search(const std::vector<TickObj<MuseMsg *> > *pMidi, Sch::Tick tick) {
39 mTick = tick;
40 for (std::vector<TickObj<MuseMsg *> >::const_iterator it = pMidi->begin();
41 it != pMidi->end();
42 ++it) {
43 Dispatch(it->mValue);
44 }
45 }
46
54 virtual void DispatchPriv(Message *pMsg);
55
62 int mFound;
63
64private:
75 void OnNote(NoteMsg *pNote) {
76 bool bSounding = false;
77 if (mTick.mTick < pNote->mTick) {
78 bSounding = true;
79 } else {
80 const Sch::Tick end(std::min(
81 std::max(pNote->mTick + pNote->mLength.mTick, kTickMinimum), kTickMaximum));
82 if (mTick.mTick < end.mTick) {
83 bSounding = true;
84 }
85 }
86 if (bSounding) {
87 mFound = 1;
88 }
89 }
90
91 Sch::Tick mTick;
92};
Base of every event the game passes between a MsgSource and a MsgSink.
Definition message.h:41
Receiver of engine messages.
Definition msgsink.h:37
virtual void Dispatch(Message *pMsg)
Accept a message.
int mTick
The song position, in MIDI ticks.
Definition musemsg.h:71
int mFound
Non-zero once a note sounds past mTick.
Definition notefinder.h:62
virtual void DispatchPriv(Message *pMsg)
Pass a NoteMsg to OnNote() and ignore every other message.
NoteFinder()
Start with no note found and the position at kTickInfinity.
Definition notefinder.h:25
void Search(const std::vector< TickObj< MuseMsg * > > *pMidi, Sch::Tick tick)
Pass every message of a MIDI range through Dispatch() against a position.
Definition notefinder.h:38
Event the game passes between a MsgSource and a MsgSink.
Definition notemsg.h:28
Sch::Tick mLength
The length of the note, in MIDI ticks.
Definition notemsg.h:168
Song position in MIDI ticks, printed as measure, beat, and tick.
Definition tick.h:70
int mTick
The position, in MIDI ticks at 480 per quarter note.
Definition tick.h:153
One value at one song position.
Definition tickobj.h:20
constexpr int kTickMaximum
Largest finite position, from the bound Sch::Tick::IsInRange() accepts.
Definition tick.h:18
constexpr int kTickMinimum
Smallest finite position, from the bound Sch::Tick::IsInRange() accepts.
Definition tick.h:21