fixed various audio issues

This commit is contained in:
itsmattkc
2018-06-07 03:30:54 -07:00
parent b2b3f5a14e
commit 35e03bd91b
24 changed files with 225 additions and 237 deletions
-15
View File
@@ -1,15 +0,0 @@
#ifndef TIMELINETOOLS_H
#define TIMELINETOOLS_H
enum TimelineTools {
TIMELINE_TOOL_POINTER,
TIMELINE_TOOL_EDIT,
TIMELINE_TOOL_RAZOR,
TIMELINE_TOOL_RIPPLE,
TIMELINE_TOOL_ROLLING,
TIMELINE_TOOL_SLIP,
TIMELINE_TOOL_HAND,
TIMELINE_TOOL_ZOOM
};
#endif // TIMELINETOOLS_H
+13
View File
@@ -0,0 +1,13 @@
#ifndef TIMELINETOOLS_H
#define TIMELINETOOLS_H
#define TIMELINE_TOOL_POINTER 0
#define TIMELINE_TOOL_EDIT 1
#define TIMELINE_TOOL_RAZOR 2
#define TIMELINE_TOOL_RIPPLE 3
#define TIMELINE_TOOL_ROLLING 4
#define TIMELINE_TOOL_SLIP 5
#define TIMELINE_TOOL_HAND 6
#define TIMELINE_TOOL_ZOOM 7
#endif // TIMELINETOOLS_H
+11 -12
View File
@@ -24,9 +24,7 @@ TimelineWidget::TimelineWidget(QWidget *parent) : QWidget(parent)
{
bottom_align = false;
setMouseTracking(true);
track_height = 40;
clip_pixmap = NULL;
track_height = 40;
setAcceptDrops(true);
}
@@ -35,6 +33,10 @@ bool same_sign(int a, int b) {
return (a < 0) == (b < 0);
}
void TimelineWidget::resizeEvent(QResizeEvent*) {
if (panel_timeline->sequence != NULL) redraw_clips();
}
void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) {
if (static_cast<SourceTable*>(event->source()) == panel_project->source_table) {
QPoint pos = event->pos();
@@ -77,7 +79,7 @@ void TimelineWidget::dragMoveEvent(QDragMoveEvent *event) {
}
}
void TimelineWidget::dragLeaveEvent(QDragLeaveEvent *event) {
void TimelineWidget::dragLeaveEvent(QDragLeaveEvent*) {
if (panel_timeline->importing) {
panel_timeline->ghosts.clear();
panel_timeline->importing = false;
@@ -324,7 +326,6 @@ bool subvalidate_snapping(Ghost& g, long* frame_diff, long snap_point) {
}
void validate_snapping(Ghost& g, long* frame_diff) {
long validator;
panel_timeline->snapped = false;
if (panel_timeline->snapping) {
if (!subvalidate_snapping(g, frame_diff, panel_timeline->playhead)) {
@@ -659,15 +660,13 @@ int color_brightness(int r, int g, int b) {
}
void TimelineWidget::redraw_clips() {
// Draw clips
if (clip_pixmap != NULL) delete clip_pixmap;
// Draw clips
int panel_width = getScreenPointFromFrame(panel_timeline->sequence->getEndFrame()) + 100;
setMinimumWidth(panel_width);
clip_pixmap = new QPixmap(panel_width, height());
clip_pixmap->fill(Qt::transparent);
QPainter clip_painter(clip_pixmap);
clip_pixmap = QPixmap(panel_width, height());
clip_pixmap.fill(Qt::transparent);
QPainter clip_painter(&clip_pixmap);
int video_track_limit = 0;
int audio_track_limit = 0;
for (int i=0;i<panel_timeline->sequence->clip_count();i++) {
@@ -726,7 +725,7 @@ void TimelineWidget::paintEvent(QPaintEvent*) {
if (panel_timeline->sequence != NULL) {
QPainter p(this);
if (clip_pixmap != NULL) p.drawPixmap(0, 0, minimumWidth(), height(), *clip_pixmap);
p.drawPixmap(0, 0, minimumWidth(), height(), clip_pixmap);
// Draw selections
for (int i=0;i<panel_timeline->selections.size();i++) {
+7 -3
View File
@@ -2,7 +2,7 @@
#define TIMELINEWIDGET_H
#include <QWidget>
#include "timeline-tools.h"
#include "timelinetools.h"
#define GHOST_THICKNESS 2 // thiccccc
#define CLIP_TEXT_PADDING 3
@@ -19,9 +19,10 @@ public:
bool bottom_align;
void redraw_clips();
void redraw_clips();
protected:
void paintEvent(QPaintEvent*) override;
void resizeEvent(QResizeEvent*) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
@@ -45,12 +46,15 @@ private:
QList<Clip*> pre_clips;
QList<Clip*> post_clips;
QPixmap* clip_pixmap;
QPixmap clip_pixmap;
// QPixmap selection_pixmap;
signals:
public slots:
private slots:
};
#endif // TIMELINEWIDGET_H
+21 -42
View File
@@ -17,12 +17,10 @@ extern "C" {
ViewerWidget::ViewerWidget(QWidget *parent) : QOpenGLWidget(parent)
{
multithreaded = true;
multithreaded = true;
enable_paint = true;
force_audio = false;
audio_bytes_written = 0;
QSurfaceFormat format;
format.setDepthBufferSize(24);
setFormat(format);
@@ -67,17 +65,6 @@ void ViewerWidget::paintGL()
bool render_audio = (panel_timeline->playing || force_audio);
// switch_cache
if (render_audio && audio_bytes_written == audio_cache_size) {
switch_audio_cache = true;
reading_audio_cache_A = !reading_audio_cache_A;
audio_bytes_written = 0;
clear_cache(!reading_audio_cache_A, reading_audio_cache_A);
}
// qDebug() << audio_bytes_written << "/" << audio_cache_size;
cc_lock.lock();
for (int i=0;i<current_clips.size();i++) {
Clip* c = current_clips.at(i);
@@ -124,38 +111,30 @@ void ViewerWidget::paintGL()
c->texture->release();
}
} else if (c->stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
playhead >= c->timeline_in &&
render_audio &&
!c->reached_end &&
(switch_audio_cache || c->reset_audio)) {
// TODO doesn't affect new clips appearing in the timeline (they'll ALWAYS end up in the other cache with a 1/8 sec delay)
// cache audio
if (c->lock.tryLock()) {
// clip is not caching, start cache
c->lock.unlock();
cache_clip(c, playhead, !reading_audio_cache_A, reading_audio_cache_A, c->reset_audio);
}
} else if (render_audio &&
c->stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
playhead >= c->timeline_in &&
c->lock.tryLock()) {
// clip is not caching, start caching audio
c->lock.unlock();
cache_clip(c, playhead, false, false, c->reset_audio);
}
}
}
}
if (render_audio) {
switch_audio_cache = false;
if (audio_cache_A != NULL && audio_bytes_written < audio_cache_size) {
// send cached/buffered audio to QIODevice/QAudioOutput
uint8_t* cache = reading_audio_cache_A ? audio_cache_A : audio_cache_B;
if (panel_timeline->playing) {
int max_w = audio_cache_size-audio_bytes_written;
int w = audio_io_device->write((const char*) cache+audio_bytes_written, max_w);
qDebug() << w << max_w;
audio_bytes_written += w;
}
if (panel_timeline->playing) {
int adjusted_read_index = audio_ibuffer_read%audio_ibuffer_size;
int max_write = audio_ibuffer_size - adjusted_read_index;
int actual_write = audio_io_device->write((const char*) audio_ibuffer+adjusted_read_index, max_write);
memset(audio_ibuffer+adjusted_read_index, 0, actual_write);
audio_ibuffer_read += actual_write;
if (actual_write == max_write) {
// got all the bytes, write again
actual_write = audio_io_device->write((const char*) audio_ibuffer, audio_ibuffer_size);
memset(audio_ibuffer, 0, actual_write);
audio_ibuffer_read += actual_write;
}
}
}
cc_lock.unlock();