diff --git a/src/jack.h b/src/jack.h index 90d4e51..0b06dd9 100644 --- a/src/jack.h +++ b/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 */ diff --git a/src/loop.cpp b/src/loop.cpp index bbfa75c..77713ab 100644 --- a/src/loop.cpp +++ b/src/loop.cpp @@ -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; } diff --git a/src/loop.h b/src/loop.h index e20c527..5ce84f8 100644 --- a/src/loop.h +++ b/src/loop.h @@ -23,9 +23,10 @@ typedef std::list 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 diff --git a/src/ui.cpp b/src/ui.cpp index c387df6..fc93b84 100644 --- a/src/ui.cpp +++ b/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;