2009-07-21 20:23:12 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#ifndef LOOP_H
|
|
|
|
#define LOOP_H
|
|
|
|
|
2009-07-23 07:55:39 +00:00
|
|
|
#include <stdio.h>
|
2009-07-21 20:23:12 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <list>
|
|
|
|
#include <jack/jack.h>
|
|
|
|
#include <jack/midiport.h>
|
2009-07-21 21:33:51 +00:00
|
|
|
#include "notecache.h"
|
2009-07-21 20:23:12 +00:00
|
|
|
|
|
|
|
enum LoopState {
|
|
|
|
LS_IDLE,
|
2009-07-22 13:45:36 +00:00
|
|
|
LS_SYNC,
|
|
|
|
LS_PLAY,
|
2009-07-21 20:23:12 +00:00
|
|
|
LS_STOPPING,
|
2009-07-22 07:24:44 +00:00
|
|
|
LS_RECORDING,
|
2009-07-21 20:23:12 +00:00
|
|
|
};
|
|
|
|
|
2009-07-22 19:11:57 +00:00
|
|
|
typedef std::list<jack_midi_event_t> EventList;
|
2009-07-21 20:23:12 +00:00
|
|
|
|
|
|
|
class Loop {
|
|
|
|
private:
|
|
|
|
jack_nframes_t m_length; ///< Length of loop, in samples.
|
2009-07-22 14:10:49 +00:00
|
|
|
float m_position; ///< Current position of loop, in samples.
|
2009-07-21 20:23:12 +00:00
|
|
|
LoopState m_state;
|
2009-07-22 13:45:36 +00:00
|
|
|
bool m_loop;
|
2009-07-22 14:10:49 +00:00
|
|
|
float m_tempo;
|
2009-07-21 20:23:12 +00:00
|
|
|
|
|
|
|
EventList m_events;
|
|
|
|
EventList::iterator m_iterator;
|
|
|
|
|
|
|
|
public:
|
2009-07-22 05:25:28 +00:00
|
|
|
Loop();
|
|
|
|
~Loop();
|
|
|
|
|
2009-07-21 20:23:12 +00:00
|
|
|
void PlayFrame(void *port_buffer, jack_nframes_t frame);
|
2009-07-22 19:11:57 +00:00
|
|
|
void AddEvent(jack_midi_event_t *event);
|
2009-07-21 20:23:12 +00:00
|
|
|
|
2009-07-22 07:24:44 +00:00
|
|
|
void SetState(LoopState state)
|
|
|
|
{
|
|
|
|
m_state = state;
|
|
|
|
}
|
|
|
|
|
2009-07-21 20:23:12 +00:00
|
|
|
void SetLength(jack_nframes_t length);
|
2009-07-22 13:45:36 +00:00
|
|
|
void Start(bool loop, bool sync);
|
2009-07-21 20:23:12 +00:00
|
|
|
void Stop();
|
2009-07-21 21:52:18 +00:00
|
|
|
void Empty();
|
2009-07-21 21:33:51 +00:00
|
|
|
|
|
|
|
void StartFromNoteCache(NoteCache &cache);
|
|
|
|
void EndFromNoteCache(NoteCache &cache);
|
2009-07-22 07:24:44 +00:00
|
|
|
|
|
|
|
LoopState State() const
|
|
|
|
{
|
|
|
|
return m_state;
|
|
|
|
}
|
|
|
|
|
2009-07-22 14:10:49 +00:00
|
|
|
void SetTempo(float tempo)
|
|
|
|
{
|
|
|
|
m_tempo = tempo;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Tempo() const
|
|
|
|
{
|
|
|
|
return m_tempo;
|
|
|
|
}
|
|
|
|
|
2009-07-22 07:24:44 +00:00
|
|
|
jack_nframes_t Length() const
|
|
|
|
{
|
2009-07-22 14:10:49 +00:00
|
|
|
return m_length / m_tempo;
|
2009-07-22 07:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
jack_nframes_t Position() const
|
|
|
|
{
|
2009-07-22 14:10:49 +00:00
|
|
|
return m_position / m_tempo;
|
2009-07-22 07:24:44 +00:00
|
|
|
}
|
2009-07-22 13:45:36 +00:00
|
|
|
|
|
|
|
bool Looping() const
|
|
|
|
{
|
|
|
|
return m_loop;
|
|
|
|
}
|
2009-07-23 07:55:39 +00:00
|
|
|
|
2009-07-24 07:19:13 +00:00
|
|
|
void Finalise();
|
|
|
|
|
2009-07-23 07:55:39 +00:00
|
|
|
void Save(FILE *f) const;
|
2010-03-30 16:54:24 +00:00
|
|
|
void Load(FILE *f, int file_sample_rate, int jack_sample_rate);
|
2009-07-21 20:23:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* LOOP_H */
|