-Updated BPM save / restore
parent
cf5ef0022e
commit
076727dd7b
|
@ -17,11 +17,13 @@ class AudioBuffer
|
|||
{
|
||||
ID = privateID++;
|
||||
numBeats = 0;
|
||||
audioFrames = 0;
|
||||
}
|
||||
AudioBuffer(unsigned long size)
|
||||
{
|
||||
/// no ID assigned: it *takes* the one from the previous buffer!
|
||||
numBeats = 0;
|
||||
audioFrames = 0;
|
||||
buffer.resize(size);
|
||||
}
|
||||
|
||||
|
@ -63,6 +65,19 @@ class AudioBuffer
|
|||
numBeats = b;
|
||||
}
|
||||
|
||||
void setAudioFrames(long af)
|
||||
{
|
||||
audioFrames = af;
|
||||
#ifdef DEBUG_BUFFER
|
||||
cout << "AudioBuffer " << ID << " has " << audioFrames << " audioFrames\n" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
long getAudioFrames()
|
||||
{
|
||||
return audioFrames;
|
||||
}
|
||||
|
||||
std::vector<float>& getData()
|
||||
{
|
||||
return buffer;
|
||||
|
@ -79,6 +94,10 @@ class AudioBuffer
|
|||
|
||||
int numBeats;
|
||||
|
||||
/// holds the number of samples that are usable audio, as opposed to
|
||||
/// buffer.size(), which also has non-used space at the end.
|
||||
long audioFrames;
|
||||
|
||||
char name[20];
|
||||
|
||||
std::vector<float> buffer;
|
||||
|
|
|
@ -33,6 +33,7 @@ void DiskReader::loadSample( int track, int scene, string path )
|
|||
infile.read( &buf[0] , infile.frames() );
|
||||
|
||||
// set the data
|
||||
ab->setAudioFrames( infile.frames() );
|
||||
ab->nonRtSetSample( buf );
|
||||
|
||||
cout << "Worker: loadSample() " << path << " size: " << infile.frames() << endl;
|
||||
|
@ -154,6 +155,8 @@ void DiskReader::readMaster()
|
|||
// bpm
|
||||
{
|
||||
cJSON* bpm = cJSON_GetObjectItem( master, "bpm");
|
||||
cout << "Session: BPM " << bpm->valuedouble << " int " << bpm->valueint << endl;
|
||||
|
||||
EventTimeBPM e( bpm->valuedouble );
|
||||
writeToDspRingbuffer( &e );
|
||||
}
|
||||
|
|
|
@ -65,8 +65,12 @@ void DiskWriter::writeAudioBuffer(int track, int scene, AudioBuffer* ab )
|
|||
path << sessionPath << "/" << sessionName << "/samples/" << filename.str();
|
||||
|
||||
SndfileHandle outfile( path.str(), SFM_WRITE, SF_FORMAT_WAV | SF_FORMAT_FLOAT, 1, 44100);
|
||||
cout << "Worker::writeSample() " << path.str() << " size: " << ab->getData().size() << endl;
|
||||
outfile.write( &ab->getData()[0], ab->getData().size() );
|
||||
cout << "Worker::writeSample() " << path.str() << " size: " << ab->getAudioFrames() << endl;
|
||||
|
||||
// FIXME: the size of the buffer is bigger than the audio contained in it:
|
||||
// calculate the length that needs saving using getBeats() * framesPerBeat
|
||||
|
||||
outfile.write( &ab->getData()[0], ab->getAudioFrames() );
|
||||
|
||||
// de allocate the AudioBuffer
|
||||
delete ab;
|
||||
|
|
|
@ -37,11 +37,11 @@ void LooperClip::save()
|
|||
if ( _loaded )
|
||||
{
|
||||
char buffer [50];
|
||||
sprintf (buffer, "LooperClip::save() track %i, scene %i", track,scene);
|
||||
sprintf (buffer, "LC::save() track %i, scene %i", track,scene);
|
||||
EventGuiPrint e( buffer );
|
||||
writeToGuiRingbuffer( &e );
|
||||
|
||||
EventRequestSaveBuffer e2( track, scene, _buffer->getData().size() );
|
||||
EventRequestSaveBuffer e2( track, scene, _buffer->getAudioFrames() );
|
||||
writeToGuiRingbuffer( &e2 );
|
||||
}
|
||||
else
|
||||
|
@ -69,7 +69,7 @@ void LooperClip::load( AudioBuffer* ab )
|
|||
_recordhead = _buffer->getData().size();
|
||||
|
||||
char buffer [50];
|
||||
sprintf (buffer, "LooperClip::load() track %i, scene %i",track, scene);
|
||||
sprintf (buffer, "LC::load() t %i, s %i, aF %i",track, scene, int(_buffer->getAudioFrames()) );
|
||||
EventGuiPrint e( buffer );
|
||||
writeToGuiRingbuffer( &e );
|
||||
|
||||
|
@ -99,11 +99,12 @@ void LooperClip::setRequestedBuffer( AudioBuffer* ab )
|
|||
void LooperClip::recieveSaveBuffer( AudioBuffer* saveBuffer )
|
||||
{
|
||||
// copy current contents into save buffer,
|
||||
size_t size = _buffer->getData().size();
|
||||
memcpy( &saveBuffer->getData().at(0), &_buffer->getData().at(0), sizeof(float)*size);
|
||||
size_t framesBySize = _buffer->getAudioFrames();
|
||||
memcpy( &saveBuffer->getData().at(0), &_buffer->getData().at(0), sizeof(float)*framesBySize);
|
||||
|
||||
saveBuffer->setID ( _buffer->getID() );
|
||||
saveBuffer->setBeats( _buffer->getBeats() );
|
||||
saveBuffer->setAudioFrames( _buffer->getAudioFrames() );
|
||||
|
||||
EventSaveBuffer e ( track, scene, saveBuffer );
|
||||
writeToGuiRingbuffer( &e );
|
||||
|
@ -217,6 +218,7 @@ void LooperClip::bar()
|
|||
{
|
||||
// FIXME: assumes 4 beats in a bar
|
||||
_buffer->setBeats( _buffer->getBeats() + 4 );
|
||||
_buffer->setAudioFrames( jack->getTimeManager()->getFpb() * _buffer->getBeats() );
|
||||
}
|
||||
|
||||
if ( change )
|
||||
|
|
|
@ -31,7 +31,7 @@ int TimeManager::getFpb()
|
|||
|
||||
void TimeManager::setBpm(float bpm)
|
||||
{
|
||||
//cout << "setBpm() " << bpm << endl;
|
||||
cout << "setBpm() " << bpm << endl;
|
||||
setFpb( 44100 / bpm * 60 );
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,10 @@ void TimeManager::registerObserver(TimeObserver* o)
|
|||
//cout << "registerObserver() " << o << endl;
|
||||
observers.push_back(o);
|
||||
o->setFpb( fpb );
|
||||
|
||||
int bpm = (44100 * 60) / fpb;
|
||||
EventTimeBPM e2( bpm );
|
||||
writeToGuiRingbuffer( &e2 );
|
||||
}
|
||||
|
||||
void TimeManager::tap()
|
||||
|
|
Loading…
Reference in New Issue