further progress on source viewer
This commit is contained in:
@@ -243,9 +243,6 @@ void Timeline::repaint_timeline(bool changed) {
|
||||
last_frame = sequence->playhead;
|
||||
}
|
||||
|
||||
panel_sequence_viewer->update_playhead_timecode(sequence->playhead);
|
||||
|
||||
|
||||
if (sequenceEndFrame > 0) {
|
||||
panel_sequence_viewer->ui->headers->update_zoom((double) panel_sequence_viewer->ui->headers->width() / (double) sequenceEndFrame);
|
||||
} else {
|
||||
|
||||
+50
-3
@@ -27,7 +27,8 @@ Viewer::Viewer(QWidget *parent) :
|
||||
ui(new Ui::Viewer),
|
||||
seq(NULL),
|
||||
queue_audio_reset(false),
|
||||
playing(false)
|
||||
playing(false),
|
||||
created_sequence(false)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->headers->viewer = this;
|
||||
@@ -53,6 +54,7 @@ Viewer::~Viewer() {
|
||||
}
|
||||
|
||||
void Viewer::set_main_sequence() {
|
||||
clean_created_seq();
|
||||
set_sequence(true, sequence);
|
||||
}
|
||||
|
||||
@@ -199,10 +201,46 @@ void Viewer::update_end_timecode() {
|
||||
}
|
||||
|
||||
void Viewer::set_media(int type, void* media) {
|
||||
clean_created_seq();
|
||||
switch (type) {
|
||||
case MEDIA_TYPE_FOOTAGE:
|
||||
{
|
||||
Media* footage = static_cast<Media*>(media);
|
||||
|
||||
seq = new Sequence();
|
||||
created_sequence = true;
|
||||
|
||||
if (footage->video_tracks.size() > 0) {
|
||||
MediaStream* video_stream = footage->video_tracks.at(0);
|
||||
seq->width = video_stream->video_width;
|
||||
seq->height = video_stream->video_height;
|
||||
seq->frame_rate = video_stream->video_frame_rate;
|
||||
|
||||
Clip* c = new Clip(seq);
|
||||
c->media = footage;
|
||||
c->media_type = type;
|
||||
c->media_stream = footage->video_tracks.at(0)->file_index;
|
||||
c->timeline_in = 0;
|
||||
c->timeline_out = footage->get_length_in_frames(seq->frame_rate);
|
||||
c->track = -1;
|
||||
c->clip_in = 0;
|
||||
c->recalculateMaxLength();
|
||||
} else {
|
||||
seq->width = 1920;
|
||||
seq->height = 1080;
|
||||
seq->frame_rate = 30;
|
||||
}
|
||||
|
||||
if (footage->audio_tracks.size() > 0) {
|
||||
MediaStream* audio_stream = footage->audio_tracks.at(0);
|
||||
seq->audio_frequency = audio_stream->audio_frequency;
|
||||
} else {
|
||||
seq->audio_frequency = 48000;
|
||||
}
|
||||
|
||||
seq->audio_layout = AV_CH_LAYOUT_STEREO;
|
||||
|
||||
set_sequence(false, seq);
|
||||
}
|
||||
break;
|
||||
case MEDIA_TYPE_SEQUENCE:
|
||||
@@ -236,11 +274,20 @@ void Viewer::update_playhead() {
|
||||
}
|
||||
|
||||
void Viewer::timer_update() {
|
||||
update_playhead_timecode(seq->playhead);
|
||||
seq->playhead = round(playhead_start + ((QDateTime::currentMSecsSinceEpoch()-start_msecs) * 0.001 * seq->frame_rate));
|
||||
if (main_sequence) panel_timeline->repaint_timeline(false);
|
||||
}
|
||||
|
||||
void Viewer::set_sequence(bool main, Sequence *s) {
|
||||
void Viewer::clean_created_seq() {
|
||||
if (created_sequence) {
|
||||
delete seq;
|
||||
seq = NULL;
|
||||
created_sequence = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Viewer::set_sequence(bool main, Sequence *s) {
|
||||
reset_all_audio();
|
||||
|
||||
main_sequence = main;
|
||||
@@ -259,7 +306,7 @@ void Viewer::set_sequence(bool main, Sequence *s) {
|
||||
ui->pushButton_4->setEnabled(!null_sequence);
|
||||
ui->pushButton_5->setEnabled(!null_sequence);
|
||||
|
||||
init_audio();
|
||||
init_audio(seq);
|
||||
|
||||
if (!null_sequence) {
|
||||
playback_updater.setInterval(qFloor(1000 / seq->frame_rate));
|
||||
|
||||
@@ -49,6 +49,8 @@ public:
|
||||
ViewerWidget* viewer_widget;
|
||||
|
||||
Ui::Viewer *ui;
|
||||
public slots:
|
||||
|
||||
private slots:
|
||||
void on_pushButton_clicked();
|
||||
void on_pushButton_5_clicked();
|
||||
@@ -58,8 +60,10 @@ private slots:
|
||||
void update_playhead();
|
||||
void timer_update();
|
||||
private:
|
||||
void clean_created_seq();
|
||||
void set_sequence(bool main, Sequence* s);
|
||||
bool main_sequence;
|
||||
bool created_sequence;
|
||||
Sequence* seq;
|
||||
bool queue_audio_reset;
|
||||
};
|
||||
|
||||
+26
-24
@@ -27,13 +27,13 @@ double audio_ibuffer_timecode = 0;
|
||||
|
||||
AudioSenderThread* audio_thread;
|
||||
|
||||
void init_audio() {
|
||||
void init_audio(Sequence* s) {
|
||||
stop_audio();
|
||||
|
||||
if (sequence != NULL) {
|
||||
if (s != NULL) {
|
||||
QAudioFormat audio_format;
|
||||
audio_format.setSampleRate(sequence->audio_frequency);
|
||||
audio_format.setChannelCount(av_get_channel_layout_nb_channels(sequence->audio_layout));
|
||||
audio_format.setSampleRate(s->audio_frequency);
|
||||
audio_format.setChannelCount(av_get_channel_layout_nb_channels(s->audio_layout));
|
||||
audio_format.setSampleSize(16);
|
||||
audio_format.setCodec("audio/pcm");
|
||||
audio_format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
@@ -136,29 +136,31 @@ int AudioSenderThread::send_audio_to_output(int offset, int max) {
|
||||
int audio_ibuffer_limit = audio_ibuffer_read + actual_write;
|
||||
|
||||
// send samples to audio monitor cache
|
||||
if (panel_timeline->ui->audio_monitor->sample_cache_offset == -1) {
|
||||
panel_timeline->ui->audio_monitor->sample_cache_offset = sequence->playhead;
|
||||
}
|
||||
int channel_count = av_get_channel_layout_nb_channels(sequence->audio_layout);
|
||||
long sample_cache_playhead = panel_timeline->ui->audio_monitor->sample_cache_offset + (panel_timeline->ui->audio_monitor->sample_cache.size()/channel_count);
|
||||
int next_buffer_offset, buffer_offset_adjusted, i;
|
||||
int buffer_offset = get_buffer_offset_from_frame(sample_cache_playhead);
|
||||
if (samples.size() != channel_count) samples.resize(channel_count);
|
||||
samples.fill(0);
|
||||
if (sequence != NULL) {
|
||||
if (panel_timeline->ui->audio_monitor->sample_cache_offset == -1) {
|
||||
panel_timeline->ui->audio_monitor->sample_cache_offset = sequence->playhead;
|
||||
}
|
||||
int channel_count = av_get_channel_layout_nb_channels(sequence->audio_layout);
|
||||
long sample_cache_playhead = panel_timeline->ui->audio_monitor->sample_cache_offset + (panel_timeline->ui->audio_monitor->sample_cache.size()/channel_count);
|
||||
int next_buffer_offset, buffer_offset_adjusted, i;
|
||||
int buffer_offset = get_buffer_offset_from_frame(sample_cache_playhead);
|
||||
if (samples.size() != channel_count) samples.resize(channel_count);
|
||||
samples.fill(0);
|
||||
|
||||
// TODO: I don't like this, but i'm not sure if there's a smarter way to do it
|
||||
while (buffer_offset < audio_ibuffer_limit) {
|
||||
sample_cache_playhead++;
|
||||
next_buffer_offset = qMin(get_buffer_offset_from_frame(sample_cache_playhead), audio_ibuffer_limit);
|
||||
while (buffer_offset < next_buffer_offset) {
|
||||
for (i=0;i<samples.size();i++) {
|
||||
buffer_offset_adjusted = buffer_offset%audio_ibuffer_size;
|
||||
samples[i] = qMax(qAbs((qint16) (((audio_ibuffer[buffer_offset_adjusted+1] & 0xFF) << 8) | (audio_ibuffer[buffer_offset_adjusted] & 0xFF))), samples[i]);
|
||||
buffer_offset += 2;
|
||||
// TODO: I don't like this, but i'm not sure if there's a smarter way to do it
|
||||
while (buffer_offset < audio_ibuffer_limit) {
|
||||
sample_cache_playhead++;
|
||||
next_buffer_offset = qMin(get_buffer_offset_from_frame(sample_cache_playhead), audio_ibuffer_limit);
|
||||
while (buffer_offset < next_buffer_offset) {
|
||||
for (i=0;i<samples.size();i++) {
|
||||
buffer_offset_adjusted = buffer_offset%audio_ibuffer_size;
|
||||
samples[i] = qMax(qAbs((qint16) (((audio_ibuffer[buffer_offset_adjusted+1] & 0xFF) << 8) | (audio_ibuffer[buffer_offset_adjusted] & 0xFF))), samples[i]);
|
||||
buffer_offset += 2;
|
||||
}
|
||||
}
|
||||
panel_timeline->ui->audio_monitor->sample_cache.append(samples);
|
||||
buffer_offset = next_buffer_offset;
|
||||
}
|
||||
panel_timeline->ui->audio_monitor->sample_cache.append(samples);
|
||||
buffer_offset = next_buffer_offset;
|
||||
}
|
||||
|
||||
memset(audio_ibuffer+offset, 0, actual_write);
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ extern long audio_ibuffer_frame;
|
||||
extern double audio_ibuffer_timecode;
|
||||
void clear_audio_ibuffer();
|
||||
|
||||
void init_audio();
|
||||
void init_audio(Sequence *s);
|
||||
void stop_audio();
|
||||
int get_buffer_offset_from_frame(long frame);
|
||||
|
||||
|
||||
+8
-3
@@ -129,9 +129,14 @@ void SourceTable::mouseDoubleClickEvent(QMouseEvent* ) {
|
||||
panel_project->import_dialog();
|
||||
} else if (selectedItems().count() == 1) {
|
||||
QTreeWidgetItem* item = selectedItems().at(0);
|
||||
if (get_type_from_tree(item) == MEDIA_TYPE_SEQUENCE) {
|
||||
undo_stack.push(new ChangeSequenceAction(get_sequence_from_tree(item)));
|
||||
}
|
||||
switch (get_type_from_tree(item)) {
|
||||
case MEDIA_TYPE_FOOTAGE:
|
||||
panel_footage_viewer->set_media(get_type_from_tree(item), get_media_from_tree(item));
|
||||
break;
|
||||
case MEDIA_TYPE_SEQUENCE:
|
||||
undo_stack.push(new ChangeSequenceAction(get_sequence_from_tree(item)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user