-Add: Tempo changing.
git-svn-id: http://svn.fuzzle.org/mloop/trunk@18 ba049829-c6ef-42ef-81ac-908dd8d2e907master
parent
981e3454e7
commit
4c351d1eff
18
src/jack.h
18
src/jack.h
|
@ -60,25 +60,35 @@ public:
|
|||
return m_recording;
|
||||
}
|
||||
|
||||
float LoopLength(int loop)
|
||||
float LoopLength(int loop) const
|
||||
{
|
||||
return (float)m_loops[loop].Length() / m_sample_rate;
|
||||
}
|
||||
|
||||
float LoopPosition(int loop)
|
||||
float LoopPosition(int loop) const
|
||||
{
|
||||
return (float)m_loops[loop].Position() / m_sample_rate;
|
||||
}
|
||||
|
||||
LoopState GetLoopState(int loop)
|
||||
LoopState GetLoopState(int loop) const
|
||||
{
|
||||
return m_loops[loop].State();
|
||||
}
|
||||
|
||||
bool LoopLooping(int loop)
|
||||
bool LoopLooping(int loop) const
|
||||
{
|
||||
return m_loops[loop].Looping();
|
||||
}
|
||||
|
||||
void SetTempo(int loop, float tempo)
|
||||
{
|
||||
m_loops[loop].SetTempo(tempo);
|
||||
}
|
||||
|
||||
float GetTempo(int loop) const
|
||||
{
|
||||
return m_loops[loop].Tempo();
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* JACK_H */
|
||||
|
|
|
@ -6,6 +6,7 @@ Loop::Loop()
|
|||
{
|
||||
m_length = 0;
|
||||
m_position = 0;
|
||||
m_tempo = 1.0;
|
||||
m_state = LS_IDLE;
|
||||
}
|
||||
|
||||
|
@ -40,9 +41,9 @@ void Loop::PlayFrame(void *port_buffer, jack_nframes_t frame)
|
|||
jack_midi_event_write(port_buffer, frame, event.buffer, event.size);
|
||||
}
|
||||
|
||||
m_position++;
|
||||
m_position += m_tempo;
|
||||
|
||||
if (m_position == m_length) {
|
||||
if (m_position >= m_length) {
|
||||
if (!m_loop) {
|
||||
m_state = LS_IDLE;
|
||||
}
|
||||
|
|
17
src/loop.h
17
src/loop.h
|
@ -23,9 +23,10 @@ typedef std::list<Event> EventList;
|
|||
class Loop {
|
||||
private:
|
||||
jack_nframes_t m_length; ///< Length of loop, in samples.
|
||||
jack_nframes_t m_position; ///< Current position of loop, in samples.
|
||||
float m_position; ///< Current position of loop, in samples.
|
||||
LoopState m_state;
|
||||
bool m_loop;
|
||||
float m_tempo;
|
||||
|
||||
EventList m_events;
|
||||
EventList::iterator m_iterator;
|
||||
|
@ -55,14 +56,24 @@ public:
|
|||
return m_state;
|
||||
}
|
||||
|
||||
void SetTempo(float tempo)
|
||||
{
|
||||
m_tempo = tempo;
|
||||
}
|
||||
|
||||
float Tempo() const
|
||||
{
|
||||
return m_tempo;
|
||||
}
|
||||
|
||||
jack_nframes_t Length() const
|
||||
{
|
||||
return m_length;
|
||||
return m_length / m_tempo;
|
||||
}
|
||||
|
||||
jack_nframes_t Position() const
|
||||
{
|
||||
return m_position;
|
||||
return m_position / m_tempo;
|
||||
}
|
||||
|
||||
bool Looping() const
|
||||
|
|
14
src/ui.cpp
14
src/ui.cpp
|
@ -154,7 +154,7 @@ bool UI::Run(Jack &j)
|
|||
bkgdset(color_map[0]);
|
||||
attrset(color_map[0]);
|
||||
|
||||
snprintf(buf, sizeof buf, " [ ] %2d: Position: %0.2f beats (%0.2fs) Length: %0.2f beats (%0.2fs)", i, m_bpm * j.LoopPosition(i) / 60.0, j.LoopPosition(i), m_bpm * j.LoopLength(i) / 60.0, j.LoopLength(i));
|
||||
snprintf(buf, sizeof buf, " [ ] %2d: Position: %0.2f beats (%0.2fs) Length: %0.2f beats (%0.2fs) Tempo: %0.1f%%", i, m_bpm * j.LoopPosition(i) / 60.0, j.LoopPosition(i), m_bpm * j.LoopLength(i) / 60.0, j.LoopLength(i), j.GetTempo(i) * 100);
|
||||
mvaddstr(i + y_offs, 0, buf);
|
||||
clrtoeol();
|
||||
|
||||
|
@ -282,6 +282,18 @@ bool UI::Run(Jack &j)
|
|||
}
|
||||
break;
|
||||
|
||||
case KEY_LEFT:
|
||||
if (m_edit_mode == EM_LOOPS) {
|
||||
j.SetTempo(m_loop, j.GetTempo(m_loop) - 0.001);
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY_RIGHT:
|
||||
if (m_edit_mode == EM_LOOPS) {
|
||||
j.SetTempo(m_loop, j.GetTempo(m_loop) + 0.001);
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY_BACKSPACE:
|
||||
if (m_edit_mode == EM_BPM) {
|
||||
m_bpm /= 10;
|
||||
|
|
Loading…
Reference in New Issue