From 8606ec2a6ea45a4a5b0e792ea3303836f08c6f60 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Thu, 29 Nov 2012 23:11:50 -0600 Subject: [PATCH] Added wave_color attribute to the clip object, which now allows the audio wave form to animate it's color along a curve over time. Combined with the timeline background color curve, some cool combinations can be made! --- include/Clip.h | 4 ++++ include/Color.h | 29 +++++++++++++++++++++++++++++ include/Frame.h | 4 ++-- include/Timeline.h | 7 +------ src/Clip.cpp | 3 +++ src/Frame.cpp | 12 ++++++------ src/Main.cpp | 13 ++++++++++--- src/Timeline.cpp | 9 ++++++++- 8 files changed, 63 insertions(+), 18 deletions(-) create mode 100644 include/Color.h diff --git a/include/Clip.h b/include/Clip.h index a1862b05..1f465614 100644 --- a/include/Clip.h +++ b/include/Clip.h @@ -13,6 +13,7 @@ #endif #include +#include "Color.h" #include "FFmpegReader.h" #include "FrameRate.h" #include "FrameMapper.h" @@ -169,6 +170,9 @@ namespace openshot { Keyframe time; /// GetWaveform(int width, int height); + tr1::shared_ptr GetWaveform(int width, int height, int Red, int Green, int Blue); /// Get an audio waveform image pixels - const Magick::PixelPacket* GetWaveformPixels(int width, int height); + const Magick::PixelPacket* GetWaveformPixels(int width, int height, int Red, int Green, int Blue); /// Get height of image int GetWidth(); diff --git a/include/Timeline.h b/include/Timeline.h index b5500455..9ac8b8ac 100644 --- a/include/Timeline.h +++ b/include/Timeline.h @@ -12,6 +12,7 @@ #include #include "Magick++.h" #include "Cache.h" +#include "Color.h" #include "Clip.h" #include "FileReaderBase.h" #include "Fraction.h" @@ -30,12 +31,6 @@ namespace openshot { return lhs->Position() <= rhs->Position() && lhs->Layer() < rhs->Layer(); }}; - struct Color{ - Keyframe red; /// Frame::GetWaveform(int width, int height) +tr1::shared_ptr Frame::GetWaveform(int width, int height, int Red, int Green, int Blue) { // Clear any existing waveform image ClearWaveform(); // Init a list of lines list lines; - lines.push_back(Magick::DrawableFillColor("#0070ff")); + lines.push_back(Magick::DrawableFillColor(Magick::Color(Red, Green, Blue))); lines.push_back(Magick::DrawablePointSize(16)); // Calculate 1/2 the width of an image based on the # of samples @@ -165,7 +165,7 @@ tr1::shared_ptr Frame::GetWaveform(int width, int height) int X = 0; // Change stroke and color - lines.push_back(Magick::DrawableStrokeColor("#0070ff")); + lines.push_back(Magick::DrawableStrokeColor(Magick::Color(Red, Green, Blue))); lines.push_back(Magick::DrawableStrokeWidth(1)); // Get audio for this channel @@ -242,10 +242,10 @@ void Frame::ClearWaveform() } // Get an audio waveform image pixels -const Magick::PixelPacket* Frame::GetWaveformPixels(int width, int height) +const Magick::PixelPacket* Frame::GetWaveformPixels(int width, int height, int Red, int Green, int Blue) { // Get audio wave form image - wave_image = GetWaveform(width, height); + wave_image = GetWaveform(width, height, Red, Green, Blue); // Return array of pixel packets return wave_image->getConstPixels(0,0, wave_image->columns(), wave_image->rows()); @@ -255,7 +255,7 @@ const Magick::PixelPacket* Frame::GetWaveformPixels(int width, int height) void Frame::DisplayWaveform() { // Get audio wave form image - GetWaveform(720, 480); + GetWaveform(720, 480, 0, 28672, 65280); // Display Image wave_image->display(); diff --git a/src/Main.cpp b/src/Main.cpp index ff2a9507..ad805f5e 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -60,10 +60,10 @@ int main() // Add some clips //Clip c1(new FFmpegReader("/home/jonathan/Apps/videcho_site/media/user_files/videos/bd0bf442-3221-11e2-8bf6-001fd00ee3aa.webm")); - Clip c1(new FFmpegReader("/home/jonathan/Music/lonely island/B004YRCAIU_(disc_1)_02_-_Mama_[Explicit].mp3")); + Clip c1(new FFmpegReader("/home/jonathan/Videos/Movie Music/02 - Shattered [Turn The Car Around] (Album Version).mp3")); //Clip c1(new FFmpegReader("/home/jonathan/sintel.webm")); - Clip c2(new ImageReader("/home/jonathan/Desktop/openshot_style1.png")); - Clip c3(new FFmpegReader("/home/jonathan/Music/lonely island/B004YRCAUI_(disc_1)_16_-_Japan.mp3")); + Clip c2(new ImageReader("/home/jonathan/Desktop/Logo.png")); + Clip c3(new FFmpegReader("/home/jonathan/Videos/Movie Music/01 Whip It.mp3")); //Clip c3(new FFmpegReader("/home/jonathan/Desktop/IncognitoCory_-_April_Song.mp3")); c1.Position(0.0); c1.gravity = GRAVITY_CENTER; @@ -74,7 +74,14 @@ int main() c1.volume.AddPoint(100, 0.5); c1.volume.AddPoint(200, 0.0); c1.volume.AddPoint(300, 0.5); + c1.Waveform(true); +// c1.wave_color.blue.AddPoint(1, 0); +// c1.wave_color.red.AddPoint(1, 65280); +// c1.wave_color.red.AddPoint(300, 0); +// c1.wave_color.green.AddPoint(1, 0); +// c1.wave_color.green.AddPoint(300, 65280); + //c1.scale_x.AddPoint(1, 0.5, LINEAR); //c1.scale_y.AddPoint(1, 0.5, LINEAR); diff --git a/src/Timeline.cpp b/src/Timeline.cpp index 46a17bfc..26b3a30d 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -98,8 +98,15 @@ void Timeline::add_layer(tr1::shared_ptr new_frame, Clip* source_clip, in // Get actual frame image data source_image = source_frame->GetImage(); else + { + // Get the color of the waveform + int red = source_clip->wave_color.red.GetInt(timeline_frame_number); + int green = source_clip->wave_color.green.GetInt(timeline_frame_number); + int blue = source_clip->wave_color.blue.GetInt(timeline_frame_number); + // Generate Waveform Dynamically (the size of the timeline) - source_image = source_frame->GetWaveform(width, height); + source_image = source_frame->GetWaveform(width, height, red, green, blue); + } // Get some basic image properties int source_width = source_image->columns();