Set tempo with recorded loop in free mode

main
Georg Krause 2019-06-06 14:17:50 +02:00
parent f41d76b3d7
commit 994ead34ff
5 changed files with 53 additions and 11 deletions

View File

@ -108,6 +108,7 @@ void AudioEditor::show( AudioBuffer* buf, bool modal )
const auto size = tmp.size();
waveform->setData( tmp );
// TODO 4 beats/bar
const int beats[]= {1,2,4,8,16,32,64};
int iBeatOne = -1;

View File

@ -152,8 +152,14 @@ void GridLogic::pressed( int track, int scene )
to->recordArm(false);
jack->getControllerUpdater()->recordArm( track, false );
} else {
if ( s == STATE_EMPTY )
lc->queueRecord();
if(s == STATE_EMPTY) {
if(!jack->getFreeRecMode()) {
lc->queueRecord();
} else {
cout << "Instant Rec!!\n";
lc->setRecording();
}
}
if ( s == STATE_STOPPED ) {
// hack, stop all scenes, then launch proper one
@ -170,8 +176,14 @@ void GridLogic::pressed( int track, int scene )
if ( s == STATE_PLAYING )
lc->queueStop();
if ( s == STATE_RECORDING )
lc->queuePlay();
if(s == STATE_RECORDING) {
if(!jack->getFreeRecMode()) {
lc->queuePlay();
} else {
lc->processFreeRec();
// lc->setPlaying();
}
}
if ( s == STATE_PLAY_QUEUED )
lc->queueStop();

View File

@ -217,7 +217,9 @@ void LooperClip::record(int count, float* L, float* R)
}
_loaded = true;
_recFpb = jack->getTimeManager()->getFpb();
if(!jack->getFreeRecMode()) {
_recFpb = jack->getTimeManager()->getFpb();
}
}
unsigned long LooperClip::recordSpaceAvailable()
@ -269,7 +271,7 @@ LooperClip::bar()
if(_playing) {
_barsPlayed++;
}
if(_recording) {
if(_recording && !jack->getFreeRecMode()) {
_barsRecorded++;
}
@ -285,7 +287,7 @@ LooperClip::bar()
_barsRecorded == jack->getClipLength() - 1) {
queuePlay();
}
if(_recording) {
if(_recording && !jack->getFreeRecMode()) {
// FIXME: assumes 4 beats in a bar
_buffer->setBeats(_buffer->getBeats() + 4);
_buffer->setAudioFrames(
@ -298,8 +300,11 @@ LooperClip::beat()
{
if(_playing) {
_beatsPlayed++;
cout << "Beat Num: "
<< jack->getTimeManager()->getBeatCounter() % 4 << "\n";
}
if(_playing && _beatsPlayed >= (getBeats() / _playbackSpeed)) {
cout << "Beats Played: " << _beatsPlayed << "\n";
resetPlayHead();
}
}
@ -505,6 +510,23 @@ float LooperClip::getPlayhead()
return _playhead;
}
void LooperClip::processFreeRec() {
setStopped();
int max_beats =
(MAX_TEMPO * _recordhead) / (jack->getSamplerate() * 60);
// calculate lower multiple of 4
int beats = (int)(max_beats/4)*4; // TODO 4 beats/bar
cout << _recordhead << " " << beats << "\n";
_buffer->setBeats(beats);
_buffer->setAudioFrames(
_recordhead);
_barsRecorded = beats / 4; // TODO 4 beats/bar
_recFpb = _recordhead / beats;
jack->getTimeManager()->setFpb(_recFpb);
jack->getTimeManager()->setTransportState(TRANSPORT_ROLLING);
queuePlay();
}
#ifdef BUILD_TESTS
void LooperClip::setState( bool load, bool play, bool rec, bool qPlay, bool qStop, bool qRec )
{

View File

@ -123,6 +123,13 @@ public:
/// reset the play head to zero. Does nothing when recording
void resetPlayHead();
/// Change State to Recording
void setRecording();
/// Change State to Playing
void setPlaying();
void processFreeRec();
#ifdef BUILD_TESTS
// used only in test cases
void setState( bool load, bool play, bool rec, bool qPlay, bool qStop, bool qRec );
@ -165,10 +172,6 @@ private:
/// Get available Space to record
unsigned long recordSpaceAvailable();
/// Change State to Playing
void setPlaying();
/// Change State to Recording
void setRecording();
/// Change State to Stopped
void setStopped();

View File

@ -59,6 +59,10 @@ public:
/// TRANSPORT_STATE is defined in transport.hxx
void setTransportState( TRANSPORT_STATE s );
int getBeatCounter() {
return beatCounter;
}
private:
int samplerate;