From aba0b5db116db658d1d90c289c2dbb47684c600d Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 12 Mar 2012 00:07:16 +0000 Subject: [PATCH] Add support for the Selected style to the audio renderers Originally committed to SVN as r6570. --- aegisub/src/audio_colorscheme.cpp | 4 ++-- aegisub/src/audio_renderer.cpp | 2 +- aegisub/src/audio_renderer_spectrum.cpp | 21 +++++------------- aegisub/src/audio_renderer_spectrum.h | 13 ++--------- aegisub/src/audio_renderer_waveform.cpp | 23 +++++-------------- aegisub/src/audio_renderer_waveform.h | 16 +++----------- aegisub/src/audio_rendering_style.h | 2 +- aegisub/src/libresrc/default_config.json | 28 ++++++++++++------------ 8 files changed, 35 insertions(+), 74 deletions(-) diff --git a/aegisub/src/audio_colorscheme.cpp b/aegisub/src/audio_colorscheme.cpp index f51d7460f..a413e4a84 100644 --- a/aegisub/src/audio_colorscheme.cpp +++ b/aegisub/src/audio_colorscheme.cpp @@ -57,8 +57,8 @@ AudioColorScheme::AudioColorScheme(int prec, std::string const& scheme_name, int { case AudioStyle_Normal: opt_base += "Normal/"; break; case AudioStyle_Inactive: opt_base += "Inactive/"; break; - case AudioStyle_Selected: opt_base += "Active/"; break; - case AudioStyle_Primary: opt_base += "Selected/"; break; + case AudioStyle_Selected: opt_base += "Selection/"; break; + case AudioStyle_Primary: opt_base += "Primary/"; break; default: throw agi::InternalError("Unknown audio rendering styling", 0); } diff --git a/aegisub/src/audio_renderer.cpp b/aegisub/src/audio_renderer.cpp index b6da0d76d..9c03f486d 100644 --- a/aegisub/src/audio_renderer.cpp +++ b/aegisub/src/audio_renderer.cpp @@ -173,7 +173,7 @@ void AudioRenderer::SetCacheMaxSize(size_t max_size) // bitmap cache should be plenty even if working with a one hour audio clip. cache_bitmap_maxsize = std::min(max_size/8, 0x1000000); // The renderer gets whatever is left. - cache_renderer_maxsize = max_size - 2*cache_bitmap_maxsize; + cache_renderer_maxsize = max_size - 4*cache_bitmap_maxsize; } diff --git a/aegisub/src/audio_renderer_spectrum.cpp b/aegisub/src/audio_renderer_spectrum.cpp index 9e62bf265..d14f17d44 100644 --- a/aegisub/src/audio_renderer_spectrum.cpp +++ b/aegisub/src/audio_renderer_spectrum.cpp @@ -105,10 +105,7 @@ public: AudioSpectrumRenderer::AudioSpectrumRenderer(std::string const& color_scheme_name) -: colors_normal(new AudioColorScheme(12, color_scheme_name, AudioStyle_Normal)) -, colors_primary(new AudioColorScheme(12, color_scheme_name, AudioStyle_Primary)) -, colors_inactive(new AudioColorScheme(12, color_scheme_name, AudioStyle_Inactive)) -, derivation_size(8) +: derivation_size(8) , derivation_dist(8) #ifdef WITH_FFTW3 , dft_plan(0) @@ -116,6 +113,9 @@ AudioSpectrumRenderer::AudioSpectrumRenderer(std::string const& color_scheme_nam , dft_output(0) #endif { + colors.reserve(AudioStyle_MAX); + for (int i = 0; i < AudioStyle_MAX; ++i) + colors.push_back(AudioColorScheme(12, color_scheme_name, i)); } AudioSpectrumRenderer::~AudioSpectrumRenderer() @@ -256,7 +256,7 @@ void AudioSpectrumRenderer::Render(wxBitmap &bmp, int start, AudioRenderingStyle ptrdiff_t stride = img.GetWidth()*3; int imgheight = img.GetHeight(); - const AudioColorScheme *pal = GetColorScheme(style); + const AudioColorScheme *pal = &colors[style]; /// @todo Make minband and maxband configurable int minband = 0; @@ -315,7 +315,7 @@ void AudioSpectrumRenderer::Render(wxBitmap &bmp, int start, AudioRenderingStyle void AudioSpectrumRenderer::RenderBlank(wxDC &dc, const wxRect &rect, AudioRenderingStyle style) { // Get the colour of silence - wxColour col = GetColorScheme(style)->get(0.0f); + wxColour col = colors[style].get(0.0f); dc.SetBrush(wxBrush(col)); dc.SetPen(wxPen(col)); dc.DrawRectangle(rect); @@ -326,12 +326,3 @@ void AudioSpectrumRenderer::AgeCache(size_t max_size) if (cache) cache->Age(max_size); } -const AudioColorScheme *AudioSpectrumRenderer::GetColorScheme(AudioRenderingStyle style) const -{ - switch (style) - { - case AudioStyle_Primary: return colors_primary.get(); - case AudioStyle_Inactive: return colors_inactive.get(); - default: return colors_normal.get(); - } -} diff --git a/aegisub/src/audio_renderer_spectrum.h b/aegisub/src/audio_renderer_spectrum.h index 0e8d8d2c5..55e14f7bb 100644 --- a/aegisub/src/audio_renderer_spectrum.h +++ b/aegisub/src/audio_renderer_spectrum.h @@ -63,14 +63,8 @@ class AudioSpectrumRenderer : public AudioRendererBitmapProvider { /// Internal cache management for the spectrum agi::scoped_ptr cache; - /// Colour table used for regular rendering - agi::scoped_ptr colors_normal; - - /// Colour table used for rendering the audio selection - agi::scoped_ptr colors_primary; - - /// Colour table used for rendering inactive lines - agi::scoped_ptr colors_inactive; + /// Colour tables used for rendering + std::vector colors; /// Binary logarithm of number of samples to use in deriving frequency-power data size_t derivation_size; @@ -116,9 +110,6 @@ class AudioSpectrumRenderer : public AudioRendererBitmapProvider { /// Pre-allocated scratch area for storing raw audio data std::vector audio_scratch; - /// Get the color scheme for a rendering style - const AudioColorScheme *GetColorScheme(AudioRenderingStyle style) const; - public: /// @brief Constructor /// @param color_scheme_name Name of the color scheme to use diff --git a/aegisub/src/audio_renderer_waveform.cpp b/aegisub/src/audio_renderer_waveform.cpp index ee0e68f8a..062faf688 100644 --- a/aegisub/src/audio_renderer_waveform.cpp +++ b/aegisub/src/audio_renderer_waveform.cpp @@ -59,15 +59,14 @@ enum { }; AudioWaveformRenderer::AudioWaveformRenderer(std::string const& color_scheme_name) -: colors_normal(new AudioColorScheme(6, color_scheme_name, AudioStyle_Normal)) -, colors_primary(new AudioColorScheme(6, color_scheme_name, AudioStyle_Primary)) -, colors_inactive(new AudioColorScheme(6, color_scheme_name, AudioStyle_Inactive)) -, audio_buffer(0) +: audio_buffer(0) , render_averages(OPT_GET("Audio/Display/Waveform Style")->GetInt() == Waveform_MaxAvg) { + colors.reserve(AudioStyle_MAX); + for (int i = 0; i < AudioStyle_MAX; ++i) + colors.push_back(AudioColorScheme(6, color_scheme_name, i)); } - AudioWaveformRenderer::~AudioWaveformRenderer() { delete[] audio_buffer; @@ -80,7 +79,7 @@ void AudioWaveformRenderer::Render(wxBitmap &bmp, int start, AudioRenderingStyle wxRect rect(wxPoint(0, 0), bmp.GetSize()); int midpoint = rect.height / 2; - const AudioColorScheme *pal = GetColorScheme(style); + const AudioColorScheme *pal = &colors[style]; int pixel_samples = (pixel_ms * provider->GetSampleRate() + 500) / 1000; @@ -153,7 +152,7 @@ void AudioWaveformRenderer::Render(wxBitmap &bmp, int start, AudioRenderingStyle void AudioWaveformRenderer::RenderBlank(wxDC &dc, const wxRect &rect, AudioRenderingStyle style) { - const AudioColorScheme *pal = GetColorScheme(style); + const AudioColorScheme *pal = &colors[style]; wxColor line(pal->get(1.0)); wxColor bg(pal->get(0.0)); @@ -182,16 +181,6 @@ void AudioWaveformRenderer::OnSetMillisecondsPerPixel() audio_buffer = 0; } -const AudioColorScheme *AudioWaveformRenderer::GetColorScheme(AudioRenderingStyle style) const -{ - switch (style) - { - case AudioStyle_Primary: return colors_primary.get(); - case AudioStyle_Inactive: return colors_inactive.get(); - default: return colors_normal.get(); - } -} - wxArrayString AudioWaveformRenderer::GetWaveformStyles() { wxArrayString ret; ret.push_back(_("Maximum")); diff --git a/aegisub/src/audio_renderer_waveform.h b/aegisub/src/audio_renderer_waveform.h index 570710fe3..ed930d4f8 100644 --- a/aegisub/src/audio_renderer_waveform.h +++ b/aegisub/src/audio_renderer_waveform.h @@ -37,23 +37,16 @@ #ifndef AGI_PRE #include +#include #endif -#include - class AudioColorScheme; #include "audio_renderer.h" class AudioWaveformRenderer : public AudioRendererBitmapProvider { - /// Colour table used for regular rendering - agi::scoped_ptr colors_normal; - - /// Colour table used for rendering the audio selection - agi::scoped_ptr colors_primary; - - /// Colour table used for rendering inactive lines - agi::scoped_ptr colors_inactive; + /// Colour tables used for rendering + std::vector colors; /// Pre-allocated buffer for audio fetched from provider char *audio_buffer; @@ -61,9 +54,6 @@ class AudioWaveformRenderer : public AudioRendererBitmapProvider { /// Whether to render max+avg or just max bool render_averages; - /// Get the color scheme for a rendering style - const AudioColorScheme *GetColorScheme(AudioRenderingStyle style) const; - void OnSetProvider(); void OnSetMillisecondsPerPixel(); diff --git a/aegisub/src/audio_rendering_style.h b/aegisub/src/audio_rendering_style.h index c62abdb39..3e0875fb4 100644 --- a/aegisub/src/audio_rendering_style.h +++ b/aegisub/src/audio_rendering_style.h @@ -36,7 +36,7 @@ /// overlap inactive, which should overlap normal regions. enum AudioRenderingStyle { /// Regular audio with no special properties - AudioStyle_Normal, + AudioStyle_Normal = 0, /// Audio belonging to objects that are not part of the current selection AudioStyle_Inactive, /// Audio belonging to objects that are part of the current selection, diff --git a/aegisub/src/libresrc/default_config.json b/aegisub/src/libresrc/default_config.json index 1332e48ec..f2d3704de 100644 --- a/aegisub/src/libresrc/default_config.json +++ b/aegisub/src/libresrc/default_config.json @@ -126,15 +126,15 @@ "Lightness Offset" : 0.0, "Lightness Scale" : 100.0 }, - "Active" : { - "Hue Offset" : 85.0, + "Selection" : { + "Hue Offset" : 80.0, "Hue Scale" : 0.0, "Saturation Offset" : 255.0, "Saturation Scale" : 0.0, - "Lightness Offset" : 0.0, - "Lightness Scale" : 0.0 + "Lightness Offset" : 10.0, + "Lightness Scale" : 175.0 }, - "Selected" : { + "Primary" : { "Hue Offset" : 85.0, "Hue Scale" : 0.0, "Saturation Offset" : 128.0, @@ -163,6 +163,14 @@ "Lightness Scale" : 255.0 }, "Inactive" : { + "Hue Offset" : 191.0, + "Hue Scale" : -128.0, + "Saturation Offset" : 63.0, + "Saturation Scale" : 192.0, + "Lightness Offset" : 32.0, + "Lightness Scale" : 192.0 + }, + "Selection" : { "Hue Offset" : 191.0, "Hue Scale" : -128.0, "Saturation Offset" : 127.0, @@ -170,15 +178,7 @@ "Lightness Offset" : 32.0, "Lightness Scale" : 192.0 }, - "Active" : { - "Hue Offset" : 191.0, - "Hue Scale" : -128.0, - "Saturation Offset" : 127.0, - "Saturation Scale" : 128.0, - "Lightness Offset" : 0.0, - "Lightness Scale" : 0.0 - }, - "Selected" : { + "Primary" : { "Hue Offset" : 191.0, "Hue Scale" : -128.0, "Saturation Offset" : 127.0,