void NavigatorScene::mouseMoveEvent(QGraphicsSceneMouseEvent* ev) { if(ev->buttons() & (Qt::LeftButton | Qt::RightButton)) { if(ev->modifiers() & Qt::ShiftModifier) emit updatePlayhead(ev->scenePos().x()); emit centerCanvas(ev->scenePos().x(), ev->scenePos().y()); } }
const float* MovedSound::readSample() { bool playhead_was_negative = playhead < getStartTime(); cursor_position_in_buffer ++; updatePlayhead(); if (playhead >= getStartTime() && playhead_was_negative) { fillBuffer(); } int channels = (sound != NULL ? sound->getChannels() : MAX_CHANNELS); if (buffer_actual_size > 0) { if (cursor_position_in_buffer >= buffer_allocated_size) { fillBuffer(); } for (int i = 0; i < channels; i++) { read_buffer[i] = buffer[i][cursor_position_in_buffer]; } } else { for (int i = 0; i < channels; i++) { read_buffer[i] = 0.f; } } return read_buffer; }
void VorbisFileReader::rewind(double position) { if (position < 0 || position >= length) { buffer_start_time = position; buffer_actual_size = 0; cursor_position_in_buffer = 0; } else { int ret = ov_time_seek(&vf, position); if (ret < 0) { throwVorbisError(ret, L"rewind"); } if (ret == 0) { fillBuffer(); } } updatePlayhead(); }
VorbisFileReader::VorbisFileReader(wstring file_name, int buffer_size_request) : buffer_size_request(buffer_size_request) #else VorbisFileReader::VorbisFileReader(string file_name, int buffer_size_request) : buffer_size_request(buffer_size_request) #endif { #ifdef __MINGW32__ file = _wfopen(file_name.c_str(), L"rb"); #else file = fopen(file_name.c_str(), "rb"); #endif if (file == NULL) { throwError(etCantOpen, L"constructor (1)"); } // Opening vorbis file int ret = ov_open_callbacks(file, &vf, NULL, 0, OV_CALLBACKS_NOCLOSE); if (ret < 0) { throwVorbisError(ret, L"constructor (2)"); } if (ret == 0) { // Reading the comments char **ptr = ov_comment(&vf, -1)->user_comments; vorbis_info *vi = ov_info(&vf, -1); while (*ptr) { comments.push_back(string(*ptr)); ++ptr; } bitsPerSecond = ov_bitrate(&vf, -1); channels = vi->channels; rate = vi->rate; read_buffer = new float[channels]; vendor = string(ov_comment(&vf,-1)->vendor); length = ov_time_total(&vf, -1); playhead = 0; fillBuffer(); } } VorbisFileReader::~VorbisFileReader() { delete [] read_buffer; ov_clear(&vf); if (file != NULL) fclose(file); } const float* VorbisFileReader::readSample() { bool playhead_was_negative = playhead < 0; cursor_position_in_buffer ++; updatePlayhead(); if (playhead >= 0 && playhead_was_negative) // if we have just stepped into the sound { fillBuffer(); } if (buffer_actual_size > 0) // if the buffer isn't empty { if (cursor_position_in_buffer >= buffer_actual_size) // if the buffer has run away { fillBuffer(); } for (int i = 0; i < channels; i++) // filling the read buffer with the sound buffer sample at position { read_buffer[i] = buffer[i][cursor_position_in_buffer]; } } else { for (int i = 0; i < channels; i++) // filling the read buffer with zeroes { read_buffer[i] = 0.f; } } return read_buffer; }
void NavigatorScene::mousePressEvent(QGraphicsSceneMouseEvent* ev) { if(ev->modifiers() & Qt::ShiftModifier) emit updatePlayhead(ev->scenePos().x()); emit centerCanvas(ev->scenePos().x(), ev->scenePos().y()); }