2006-01-27 01:48:59 +01:00
|
|
|
// Copyright (c) 2005, Rodrigo Braz Monteiro, Niels Martin Hansen
|
2006-01-16 22:02:54 +01:00
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file audio_box.cpp
|
|
|
|
/// @brief The entire audio area in the main UI, containing display and related toolbars
|
|
|
|
/// @ingroup audio_ui
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
2006-01-16 22:02:54 +01:00
|
|
|
#include <math.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
|
2011-08-27 08:30:42 +02:00
|
|
|
#include <wx/bmpbuttn.h>
|
2011-10-10 21:30:11 +02:00
|
|
|
#include <wx/panel.h>
|
2011-09-29 07:33:04 +02:00
|
|
|
#include <wx/slider.h>
|
2011-08-27 08:30:42 +02:00
|
|
|
#include <wx/scrolbar.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/slider.h>
|
|
|
|
#include <wx/string.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/statline.h>
|
2011-08-27 08:30:42 +02:00
|
|
|
#include <wx/textctrl.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/tglbtn.h>
|
2011-09-15 08:12:26 +02:00
|
|
|
#include <wx/toolbar.h>
|
2009-09-11 00:48:29 +02:00
|
|
|
#include <wx/laywin.h> // Keep this last so wxSW_3D is set.
|
2009-09-10 15:06:40 +02:00
|
|
|
#endif
|
|
|
|
|
2010-06-09 01:21:39 +02:00
|
|
|
#include <libaegisub/log.h>
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
#include "audio_box.h"
|
2011-08-27 08:30:42 +02:00
|
|
|
|
|
|
|
#include "include/aegisub/context.h"
|
|
|
|
#include "include/aegisub/toolbar.h"
|
|
|
|
|
2011-01-18 00:54:05 +01:00
|
|
|
#include "audio_controller.h"
|
2006-01-16 22:02:54 +01:00
|
|
|
#include "audio_display.h"
|
|
|
|
#include "audio_karaoke.h"
|
2011-09-30 22:41:56 +02:00
|
|
|
#include "audio_timing.h"
|
2011-01-18 00:54:05 +01:00
|
|
|
#include "command/command.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "libresrc/libresrc.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "main.h"
|
2006-01-16 22:02:54 +01:00
|
|
|
#include "toggle_bitmap.h"
|
2011-07-15 06:04:13 +02:00
|
|
|
#include "selection_controller.h"
|
2011-01-18 00:54:05 +01:00
|
|
|
#include "utils.h"
|
2009-07-25 18:15:13 +02:00
|
|
|
|
2011-09-29 07:33:04 +02:00
|
|
|
enum {
|
2011-09-29 07:32:58 +02:00
|
|
|
Audio_Horizontal_Zoom = 1600,
|
2010-12-08 04:36:10 +01:00
|
|
|
Audio_Vertical_Zoom,
|
2011-12-28 22:27:06 +01:00
|
|
|
Audio_Volume
|
2010-12-08 04:36:10 +01:00
|
|
|
};
|
|
|
|
|
2011-01-18 00:54:05 +01:00
|
|
|
AudioBox::AudioBox(wxWindow *parent, agi::Context *context)
|
2011-09-29 07:33:04 +02:00
|
|
|
: wxSashWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxSW_3D | wxCLIP_CHILDREN)
|
2011-01-18 00:54:05 +01:00
|
|
|
, controller(context->audioController)
|
|
|
|
, context(context)
|
2011-09-29 07:33:04 +02:00
|
|
|
, panel(new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxBORDER_RAISED))
|
|
|
|
, audioDisplay(new AudioDisplay(panel, context->audioController, context))
|
2012-02-15 22:23:52 +01:00
|
|
|
, HorizontalZoom(new wxSlider(panel, Audio_Horizontal_Zoom, OPT_GET("Audio/Zoom/Horizontal")->GetInt(), -50, 30, wxDefaultPosition, wxSize(-1, 20), wxSL_VERTICAL|wxSL_BOTH))
|
|
|
|
, VerticalZoom(new wxSlider(panel, Audio_Vertical_Zoom, OPT_GET("Audio/Zoom/Vertical")->GetInt(), 0, 100, wxDefaultPosition, wxSize(-1, 20), wxSL_VERTICAL|wxSL_BOTH|wxSL_INVERSE))
|
|
|
|
, VolumeBar(new wxSlider(panel, Audio_Volume, OPT_GET("Audio/Volume")->GetInt(), 0, 100, wxDefaultPosition, wxSize(-1, 20), wxSL_VERTICAL|wxSL_BOTH|wxSL_INVERSE))
|
2011-10-25 22:28:30 +02:00
|
|
|
, mouse_zoom_accum(0)
|
2006-01-16 22:02:54 +01:00
|
|
|
{
|
2011-09-29 07:33:04 +02:00
|
|
|
SetSashVisible(wxSASH_BOTTOM, true);
|
|
|
|
Bind(wxEVT_SASH_DRAGGED, &AudioBox::OnSashDrag, this);
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
HorizontalZoom->SetToolTip(_("Horizontal zoom"));
|
2006-02-21 01:55:16 +01:00
|
|
|
VerticalZoom->SetToolTip(_("Vertical zoom"));
|
|
|
|
VolumeBar->SetToolTip(_("Audio Volume"));
|
2011-09-29 07:33:04 +02:00
|
|
|
|
2010-05-21 03:13:36 +02:00
|
|
|
bool link = OPT_GET("Audio/Link")->GetBool();
|
2007-01-05 19:27:15 +01:00
|
|
|
if (link) {
|
|
|
|
VolumeBar->SetValue(VerticalZoom->GetValue());
|
|
|
|
VolumeBar->Enable(false);
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2006-02-21 01:55:16 +01:00
|
|
|
// VertVol sider
|
|
|
|
wxSizer *VertVol = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
VertVol->Add(VerticalZoom,1,wxEXPAND,0);
|
|
|
|
VertVol->Add(VolumeBar,1,wxEXPAND,0);
|
2008-01-22 21:36:07 +01:00
|
|
|
wxSizer *VertVolArea = new wxBoxSizer(wxVERTICAL);
|
2006-02-21 01:55:16 +01:00
|
|
|
VertVolArea->Add(VertVol,1,wxEXPAND,0);
|
2011-01-18 00:54:05 +01:00
|
|
|
|
2011-09-29 07:33:04 +02:00
|
|
|
ToggleBitmap *link_btn = new ToggleBitmap(panel, context, "audio/opt/vertical_link", 16, "Audio", wxSize(20, -1));
|
2011-08-27 08:30:42 +02:00
|
|
|
VertVolArea->Add(link_btn, 0, wxRIGHT | wxALIGN_CENTER | wxEXPAND, 0);
|
2011-09-29 07:32:58 +02:00
|
|
|
OPT_SUB("Audio/Link", &AudioBox::OnVerticalLink, this);
|
2006-02-21 01:55:16 +01:00
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
// Top sizer
|
2011-01-18 00:54:05 +01:00
|
|
|
wxSizer *TopSizer = new wxBoxSizer(wxHORIZONTAL);
|
2010-12-08 04:36:10 +01:00
|
|
|
TopSizer->Add(audioDisplay,1,wxEXPAND,0);
|
2006-01-16 22:02:54 +01:00
|
|
|
TopSizer->Add(HorizontalZoom,0,wxEXPAND,0);
|
2006-02-21 01:55:16 +01:00
|
|
|
TopSizer->Add(VertVolArea,0,wxEXPAND,0);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-29 07:33:04 +02:00
|
|
|
context->karaoke = new AudioKaraoke(panel, context);
|
2009-08-14 05:11:34 +02:00
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
// Main sizer
|
2011-01-18 00:54:05 +01:00
|
|
|
wxBoxSizer *MainSizer = new wxBoxSizer(wxVERTICAL);
|
2010-12-08 04:36:10 +01:00
|
|
|
MainSizer->Add(TopSizer,1,wxEXPAND|wxALL,3);
|
2011-09-29 07:33:04 +02:00
|
|
|
MainSizer->Add(toolbar::GetToolbar(panel, "audio", context, "Audio"),0,wxEXPAND|wxBOTTOM|wxLEFT|wxRIGHT,3);
|
2011-09-28 21:44:07 +02:00
|
|
|
MainSizer->Add(context->karaoke,0,wxEXPAND|wxBOTTOM|wxLEFT|wxRIGHT,3);
|
2011-09-29 07:33:10 +02:00
|
|
|
MainSizer->Show(context->karaoke, false);
|
2010-12-08 04:36:10 +01:00
|
|
|
MainSizer->AddSpacer(3);
|
2011-09-29 07:33:04 +02:00
|
|
|
panel->SetSizer(MainSizer);
|
|
|
|
|
|
|
|
wxSizer *audioSashSizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
audioSashSizer->Add(panel, 1, wxEXPAND);
|
|
|
|
SetSizerAndFit(audioSashSizer);
|
|
|
|
SetMinSize(wxSize(-1, OPT_GET("Audio/Display Height")->GetInt()));
|
|
|
|
SetMinimumSizeY(panel->GetSize().GetHeight());
|
2011-10-25 22:28:30 +02:00
|
|
|
|
|
|
|
audioDisplay->Bind(wxEVT_MOUSEWHEEL, &AudioBox::OnMouseWheel, this);
|
2011-01-18 00:54:05 +01:00
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-08-27 08:30:42 +02:00
|
|
|
AudioBox::~AudioBox() { }
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-29 07:33:04 +02:00
|
|
|
BEGIN_EVENT_TABLE(AudioBox,wxSashWindow)
|
2006-01-16 22:02:54 +01:00
|
|
|
EVT_COMMAND_SCROLL(Audio_Horizontal_Zoom, AudioBox::OnHorizontalZoom)
|
|
|
|
EVT_COMMAND_SCROLL(Audio_Vertical_Zoom, AudioBox::OnVerticalZoom)
|
2006-02-21 01:55:16 +01:00
|
|
|
EVT_COMMAND_SCROLL(Audio_Volume, AudioBox::OnVolume)
|
2011-12-28 22:27:06 +01:00
|
|
|
END_EVENT_TABLE()
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-10-25 22:28:30 +02:00
|
|
|
void AudioBox::OnMouseWheel(wxMouseEvent &evt) {
|
|
|
|
if (!ForwardMouseWheelEvent(audioDisplay, evt))
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool zoom = evt.CmdDown() != OPT_GET("Audio/Wheel Default to Zoom")->GetBool();
|
|
|
|
if (!zoom)
|
|
|
|
{
|
|
|
|
int amount = -evt.GetWheelRotation();
|
|
|
|
// If the user did a horizontal scroll the amount should be inverted
|
|
|
|
// for it to be natural.
|
|
|
|
if (evt.GetWheelAxis() == 1) amount = -amount;
|
|
|
|
|
|
|
|
// Reset any accumulated zoom
|
|
|
|
mouse_zoom_accum = 0;
|
|
|
|
|
|
|
|
audioDisplay->ScrollBy(amount);
|
|
|
|
}
|
|
|
|
else if (evt.GetWheelAxis() == 0)
|
|
|
|
{
|
|
|
|
mouse_zoom_accum += evt.GetWheelRotation();
|
|
|
|
int zoom_delta = mouse_zoom_accum / evt.GetWheelDelta();
|
|
|
|
mouse_zoom_accum %= evt.GetWheelDelta();
|
|
|
|
int new_zoom = audioDisplay->GetZoomLevel() + zoom_delta;
|
|
|
|
audioDisplay->SetZoomLevel(new_zoom);
|
|
|
|
HorizontalZoom->SetValue(-new_zoom);
|
2012-02-15 22:23:52 +01:00
|
|
|
OPT_SET("Audio/Zoom/Horizontal")->SetInt(new_zoom);
|
2011-10-25 22:28:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 07:33:04 +02:00
|
|
|
void AudioBox::OnSashDrag(wxSashEvent &event) {
|
|
|
|
if (event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int new_height = std::min(event.GetDragRect().GetHeight(), GetParent()->GetSize().GetHeight() - 1);
|
|
|
|
|
|
|
|
SetMinSize(wxSize(-1, new_height));
|
|
|
|
GetParent()->Layout();
|
2011-09-29 07:33:10 +02:00
|
|
|
|
|
|
|
// Karaoke mode is always disabled when the audio box is first opened, so
|
|
|
|
// the initial height shouldn't include it
|
|
|
|
if (context->karaoke->IsEnabled())
|
|
|
|
new_height -= context->karaoke->GetSize().GetHeight() + 3;
|
|
|
|
|
|
|
|
OPT_SET("Audio/Display Height")->SetInt(new_height);
|
2011-09-29 07:33:04 +02:00
|
|
|
}
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
void AudioBox::OnHorizontalZoom(wxScrollEvent &event) {
|
2010-12-08 04:36:10 +01:00
|
|
|
// Negate the value, we want zoom out to be on bottom and zoom in on top,
|
|
|
|
// but the control doesn't want negative on bottom and positive on top.
|
|
|
|
audioDisplay->SetZoomLevel(-event.GetPosition());
|
2012-02-15 22:23:52 +01:00
|
|
|
OPT_SET("Audio/Zoom/Horizontal")->SetInt(event.GetPosition());
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioBox::OnVerticalZoom(wxScrollEvent &event) {
|
2011-01-18 00:54:05 +01:00
|
|
|
int pos = mid(1, event.GetPosition(), 100);
|
2012-02-15 22:23:52 +01:00
|
|
|
OPT_SET("Audio/Zoom/Vertical")->SetInt(pos);
|
2011-01-18 00:54:05 +01:00
|
|
|
double value = pow(pos / 50.0, 3);
|
2010-12-08 04:36:10 +01:00
|
|
|
audioDisplay->SetAmplitudeScale(value);
|
2011-01-18 00:54:05 +01:00
|
|
|
if (!VolumeBar->IsEnabled()) {
|
2006-02-21 01:55:16 +01:00
|
|
|
VolumeBar->SetValue(pos);
|
2011-01-18 00:54:05 +01:00
|
|
|
controller->SetVolume(value);
|
2006-02-21 01:55:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioBox::OnVolume(wxScrollEvent &event) {
|
2011-01-18 00:54:05 +01:00
|
|
|
int pos = mid(1, event.GetPosition(), 100);
|
2012-02-15 22:23:52 +01:00
|
|
|
OPT_SET("Audio/Volume")->SetInt(pos);
|
2011-01-18 00:54:05 +01:00
|
|
|
controller->SetVolume(pow(pos / 50.0, 3));
|
2006-02-21 01:55:16 +01:00
|
|
|
}
|
|
|
|
|
2011-01-18 00:54:05 +01:00
|
|
|
void AudioBox::OnVerticalLink(agi::OptionValue const& opt) {
|
|
|
|
if (opt.GetBool()) {
|
|
|
|
int pos = mid(1, VerticalZoom->GetValue(), 100);
|
|
|
|
double value = pow(pos / 50.0, 3);
|
2010-12-08 04:36:10 +01:00
|
|
|
controller->SetVolume(value);
|
2006-02-21 01:55:16 +01:00
|
|
|
VolumeBar->SetValue(pos);
|
|
|
|
}
|
2011-01-18 00:54:05 +01:00
|
|
|
VolumeBar->Enable(!opt.GetBool());
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2011-09-29 07:33:10 +02:00
|
|
|
|
|
|
|
void AudioBox::ShowKaraokeBar(bool show) {
|
|
|
|
wxSizer *panel_sizer = panel->GetSizer();
|
2012-01-27 21:04:22 +01:00
|
|
|
if (panel_sizer->IsShown(context->karaoke) == show) return;
|
|
|
|
|
2011-09-29 07:33:10 +02:00
|
|
|
int new_height = GetSize().GetHeight();
|
|
|
|
int kara_height = context->karaoke->GetSize().GetHeight() + 3;
|
|
|
|
|
2012-01-27 21:04:22 +01:00
|
|
|
if (show)
|
2011-09-29 07:33:10 +02:00
|
|
|
new_height += kara_height;
|
2012-01-27 21:04:22 +01:00
|
|
|
else
|
|
|
|
new_height -= kara_height;
|
2011-09-29 07:33:10 +02:00
|
|
|
|
|
|
|
panel_sizer->Show(context->karaoke, show);
|
|
|
|
SetMinSize(wxSize(-1, new_height));
|
|
|
|
GetParent()->Layout();
|
|
|
|
}
|
2011-09-30 22:41:56 +02:00
|
|
|
|
|
|
|
void AudioBox::ScrollAudioBy(int pixel_amount) {
|
|
|
|
audioDisplay->ScrollBy(pixel_amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioBox::ScrollToActiveLine() {
|
|
|
|
if (controller->GetTimingController())
|
2012-02-02 00:58:58 +01:00
|
|
|
audioDisplay->ScrollTimeRangeInView(controller->GetTimingController()->GetIdealVisibleTimeRange());
|
2011-09-30 22:41:56 +02:00
|
|
|
}
|