Skip to content

Commit

Permalink
Added ability to load secondary audio files and use them with VU mete…
Browse files Browse the repository at this point in the history
…r. Proof of Concept to see if it works.
  • Loading branch information
computergeek1507 committed May 23, 2024
1 parent 8bd3a02 commit 60994eb
Show file tree
Hide file tree
Showing 27 changed files with 453 additions and 124 deletions.
6 changes: 3 additions & 3 deletions xLights/AudioManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,7 @@ void ProgressFunction(wxProgressDialog* pd, int p)
}

// Get the pre-prepared data for this frame
const FrameData* AudioManager::GetFrameData(int frame, const std::string &timing, bool needNotes)
const FrameData* AudioManager::GetFrameData(int frame, bool needNotes)
{
log4cpp::Category &logger_base = log4cpp::Category::getInstance(std::string("log_base"));

Expand Down Expand Up @@ -1757,10 +1757,10 @@ const FrameData* AudioManager::GetFrameData(int frame, const std::string &timing
return nullptr;
}

const FrameData* AudioManager::GetFrameData(const std::string &timing, long ms, bool needNotes)
const FrameData* AudioManager::GetFrameData(long ms, bool needNotes)
{
int frame = ms / _intervalMS;
return GetFrameData(frame, timing, needNotes);
return GetFrameData(frame, needNotes);
}

// Constant Bitrate Detection Functions
Expand Down
4 changes: 2 additions & 2 deletions xLights/AudioManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ class AudioManager
void SetStepBlock(int step, int block);
void SetFrameInterval(int intervalMS);
int GetFrameInterval() const { return _intervalMS; }
const FrameData* GetFrameData(int frame, const std::string &timing, bool needNotes = false);
const FrameData* GetFrameData(const std::string &timing, long ms, bool needNotes = false);
const FrameData* GetFrameData(int frame, bool needNotes = false);
const FrameData* GetFrameData(long ms, bool needNotes = false);
void DoPrepareFrameData();
void DoPolyphonicTranscription(wxProgressDialog* dlg, AudioManagerProgressCallback progresscallback);
bool IsPolyphonicTranscriptionDone() const { return _polyphonicTranscriptionDone; };
Expand Down
2 changes: 1 addition & 1 deletion xLights/PixelBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2972,7 +2972,7 @@ void PixelBufferClass::HandleLayerTransitions(int EffectPeriod, int ii) {
if (layers[ii]->use_music_sparkle_count &&
layers[ii]->buffer.GetMedia() != nullptr) {
float f = 0.0;
auto pf = layers[ii]->buffer.GetMedia()->GetFrameData(layers[ii]->buffer.curPeriod, "");
auto pf = layers[ii]->buffer.GetMedia()->GetFrameData(layers[ii]->buffer.curPeriod);
if (pf != nullptr) {
f = pf->max;
}
Expand Down
7 changes: 7 additions & 0 deletions xLights/RenderBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ AudioManager* RenderBuffer::GetMedia() const
return xLightsFrame::CurrentSeqXmlFile->GetMedia();
}

AudioManager* RenderBuffer::GetSubMedia(const std::string& audioFile) const {
if (xLightsFrame::CurrentSeqXmlFile == nullptr) {
return nullptr;
}
return xLightsFrame::CurrentSeqXmlFile->GetSubMedia(audioFile);
}

const Model* RenderBuffer::GetModel() const
{
return model;
Expand Down
1 change: 1 addition & 0 deletions xLights/RenderBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ class /*NCCDLLEXPORT*/ RenderBuffer {
RenderBuffer(RenderBuffer& buffer);
void InitBuffer(int newBufferHt, int newBufferWi, const std::string& bufferTransform, bool nodeBuffer = false);
AudioManager* GetMedia() const;
AudioManager* GetSubMedia(const std::string& audioFile) const;
const Model* GetModel() const;
const std::string &GetModelName() const;
const wxString &GetXmlHeaderInfo(HEADER_INFO_TYPES node_type) const;
Expand Down
64 changes: 63 additions & 1 deletion xLights/SeqSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const long SeqSettingsDialog::ID_BITMAPBUTTON_Xml_Media_File = wxNewId();
const long SeqSettingsDialog::ID_STATICTEXT1 = wxNewId();
const long SeqSettingsDialog::ID_TEXTCTRL1 = wxNewId();
const long SeqSettingsDialog::ID_BUTTON1 = wxNewId();
const long SeqSettingsDialog::ID_STATICTEXT2 = wxNewId();
const long SeqSettingsDialog::ID_LISTBOX_SUB_AUDIO = wxNewId();
const long SeqSettingsDialog::ID_BUTTON_ADD_SUB_AUDIO = wxNewId();
const long SeqSettingsDialog::ID_BUTTON_REMOVE_SUB_AUDIO = wxNewId();
const long SeqSettingsDialog::ID_STATICTEXT_Xml_Total_Length = wxNewId();
const long SeqSettingsDialog::ID_TEXTCTRL_Xml_Seq_Duration = wxNewId();
const long SeqSettingsDialog::ID_CHECKBOX_Overwrite_Tags = wxNewId();
Expand Down Expand Up @@ -178,6 +182,8 @@ SeqSettingsDialog::SeqSettingsDialog(wxWindow* parent, xLightsXmlFile* file_to_h
quick_start_pressed = wxArtProvider::GetBitmapBundle("xlART_quick_start_pressed", wxART_BUTTON);

//(*Initialize(SeqSettingsDialog)
wxBoxSizer* BoxSizer1;
wxBoxSizer* BoxSizer2;
wxFlexGridSizer* FlexGridSizer10;
wxFlexGridSizer* FlexGridSizer11;
wxFlexGridSizer* FlexGridSizer12;
Expand Down Expand Up @@ -247,7 +253,19 @@ SeqSettingsDialog::SeqSettingsDialog(wxWindow* parent, xLightsXmlFile* file_to_h
FlexGridSizer10->Add(-1,-1,1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button_Download = new wxButton(PanelInfo, ID_BUTTON1, _("Download Sequence and Lyrics"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
FlexGridSizer10->Add(Button_Download, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer10->Add(-1,-1,1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer10->Add(0,0,1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticText3 = new wxStaticText(PanelInfo, ID_STATICTEXT2, _("Sub Audio:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
FlexGridSizer10->Add(StaticText3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer1 = new wxBoxSizer(wxVERTICAL);
ListBoxSubAudio = new wxListBox(PanelInfo, ID_LISTBOX_SUB_AUDIO, wxDefaultPosition, wxSize(860,79), 0, 0, 0, wxDefaultValidator, _T("ID_LISTBOX_SUB_AUDIO"));
BoxSizer1->Add(ListBoxSubAudio, 1, wxALL|wxEXPAND, 5);
BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
ButtonAddSubAudio = new wxButton(PanelInfo, ID_BUTTON_ADD_SUB_AUDIO, _("Add"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON_ADD_SUB_AUDIO"));
BoxSizer2->Add(ButtonAddSubAudio, 0, wxALL, 5);
ButtonRemoveSubAudio = new wxButton(PanelInfo, ID_BUTTON_REMOVE_SUB_AUDIO, _("Remove"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON_REMOVE_SUB_AUDIO"));
BoxSizer2->Add(ButtonRemoveSubAudio, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer1->Add(BoxSizer2, 0, wxALL|wxEXPAND, 5);
FlexGridSizer10->Add(BoxSizer1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer4->Add(FlexGridSizer10, 1, wxALL|wxEXPAND, 5);
FlexGridSizer6 = new wxFlexGridSizer(0, 4, 0, 0);
StaticText_Xml_Total_Length = new wxStaticText(PanelInfo, ID_STATICTEXT_Xml_Total_Length, _("Sequence Duration:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT_Xml_Total_Length"));
Expand Down Expand Up @@ -419,6 +437,8 @@ SeqSettingsDialog::SeqSettingsDialog(wxWindow* parent, xLightsXmlFile* file_to_h
Connect(ID_CHOICE_Xml_Seq_Type,wxEVT_COMMAND_CHOICE_SELECTED,(wxObjectEventFunction)&SeqSettingsDialog::OnChoice_Xml_Seq_TypeSelect);
Connect(ID_BITMAPBUTTON_Xml_Media_File,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&SeqSettingsDialog::OnBitmapButton_Xml_Media_FileClick);
Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&SeqSettingsDialog::OnButton_DownloadClick);
Connect(ID_BUTTON_ADD_SUB_AUDIO,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&SeqSettingsDialog::OnButtonAddSubAudioClick);
Connect(ID_BUTTON_REMOVE_SUB_AUDIO,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&SeqSettingsDialog::OnButtonRemoveSubAudioClick);
Connect(ID_TEXTCTRL_Xml_Seq_Duration,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&SeqSettingsDialog::OnTextCtrl_Xml_Seq_DurationText);
Connect(ID_BITMAPBUTTON__ModifyTiming,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&SeqSettingsDialog::OnBitmapButton_ModifyTimingClick);
Connect(ID_CHECKBOX1,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&SeqSettingsDialog::OnCheckBox1Click);
Expand Down Expand Up @@ -508,6 +528,11 @@ SeqSettingsDialog::SeqSettingsDialog(wxWindow* parent, xLightsXmlFile* file_to_h
TextCtrl_Xml_Media_File->SetValue(xml_file->GetMedia()->FileName());
}
SetHash();

for (auto const& su : xml_file->GetSubMediaFiles()) {
ListBoxSubAudio->Append(su);
}

TextCtrl_Xml_Seq_Duration->ChangeValue(xml_file->GetSequenceDurationString());
BlendingCheckBox->SetValue(xml_file->supportsModelBlending());

Expand Down Expand Up @@ -1838,3 +1863,40 @@ void SeqSettingsDialog::OnButton_MusicOpenClick(wxCommandEvent& event)
}
::wxLaunchDefaultBrowser(link);
}

void SeqSettingsDialog::OnButtonAddSubAudioClick(wxCommandEvent& event)
{
wxFileDialog OpenDialog(this, "Choose Audio file", wxEmptyString, wxEmptyString, "FPP Audio Files|*.mp3;*.ogg;*.m4p;*.mp4;*.m4a;*.aac;*.wav;*.flac;*.wma;*.au;*.mkv;*.mov|xLights Audio Files|*.mp3;*.ogg;*.m4p;*.mp4;*.avi;*.wma;*.au;*.wav;*.m4a;*.mid;*.mkv;*.mov;*.mpg;*.asf;*.flv;*.mpeg;*.wmv;*.flac", wxFD_OPEN | wxFD_FILE_MUST_EXIST, wxDefaultPosition);

std::string media_directory = media_directories.empty() ? "" : media_directories.front();

if (wxDir::Exists(media_directory)) {
OpenDialog.SetDirectory(media_directory);
}

if (OpenDialog.ShowModal() == wxID_OK) {
wxString filename = OpenDialog.GetFilename();
ObtainAccessToURL(filename.ToStdString());

SetCursor(wxCURSOR_WAIT);
xml_file->AddSubMediaFile(xLightsParent->GetShowDirectory(), filename);
ListBoxSubAudio->Clear();

for (auto const& su : xml_file->GetSubMediaFiles()) {
ListBoxSubAudio->Append(su);
}

SetCursor(wxCURSOR_DEFAULT);
}
}

void SeqSettingsDialog::OnButtonRemoveSubAudioClick(wxCommandEvent& event)
{
auto su = ListBoxSubAudio->GetStringSelection();
xml_file->RemoveSubMediaFile(su);
ListBoxSubAudio->Clear();

for (auto const& su : xml_file->GetSubMediaFiles()) {
ListBoxSubAudio->Append(su);
}
}
11 changes: 11 additions & 0 deletions xLights/SeqSettingsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <wx/choice.h>
#include <wx/dialog.h>
#include <wx/gbsizer.h>
#include <wx/listbox.h>
#include <wx/notebook.h>
#include <wx/panel.h>
#include <wx/sizer.h>
Expand All @@ -46,6 +47,8 @@ class SeqSettingsDialog: public wxDialog
//(*Declarations(SeqSettingsDialog)
wxBitmapButton* BitmapButton_ModifyTiming;
wxBitmapButton* BitmapButton_Xml_Media_File;
wxButton* ButtonAddSubAudio;
wxButton* ButtonRemoveSubAudio;
wxButton* Button_Cancel;
wxButton* Button_Close;
wxButton* Button_Download;
Expand All @@ -63,12 +66,14 @@ class SeqSettingsDialog: public wxDialog
wxCheckBox* CheckBox_Overwrite_Tags;
wxChoice* Choice_Xml_Seq_Type;
wxChoice* RenderModeChoice;
wxListBox* ListBoxSubAudio;
wxNotebook* Notebook_Seq_Settings;
wxPanel* PanelInfo;
wxPanel* PanelMetaData;
wxPanel* PanelTimings;
wxPanel* Panel_DataLayers;
wxStaticText* StaticText1;
wxStaticText* StaticText3;
wxStaticText* StaticText_File;
wxStaticText* StaticText_Filename;
wxStaticText* StaticText_Info;
Expand Down Expand Up @@ -144,6 +149,10 @@ class SeqSettingsDialog: public wxDialog
static const long ID_STATICTEXT1;
static const long ID_TEXTCTRL1;
static const long ID_BUTTON1;
static const long ID_STATICTEXT2;
static const long ID_LISTBOX_SUB_AUDIO;
static const long ID_BUTTON_ADD_SUB_AUDIO;
static const long ID_BUTTON_REMOVE_SUB_AUDIO;
static const long ID_STATICTEXT_Xml_Total_Length;
static const long ID_TEXTCTRL_Xml_Seq_Duration;
static const long ID_CHECKBOX_Overwrite_Tags;
Expand Down Expand Up @@ -253,6 +262,8 @@ class SeqSettingsDialog: public wxDialog
void OnButton_EmailSendClick(wxCommandEvent& event);
void OnButton_WebsiteOpenClick(wxCommandEvent& event);
void OnButton_MusicOpenClick(wxCommandEvent& event);
void OnButtonAddSubAudioClick(wxCommandEvent& event);
void OnButtonRemoveSubAudioClick(wxCommandEvent& event);
//*)

void OnButton_Xml_Rename_TimingClick(wxCommandEvent& event);
Expand Down
4 changes: 2 additions & 2 deletions xLights/ValueCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,7 @@ float ValueCurve::GetValueAt(float offset, long startMS, long endMS)
// find the maximum of any intervening frames
float f = 0.0;
for (long ms = time; ms < time + msperPoint; ms += frameMS) {
auto pf = __audioManager->GetFrameData("", ms + frameMS);
auto pf = __audioManager->GetFrameData( ms + frameMS);
if (pf != nullptr) {
if (pf->max > f) {
f = pf->max;
Expand Down Expand Up @@ -1899,7 +1899,7 @@ float ValueCurve::GetValueAt(float offset, long startMS, long endMS)
if (__audioManager != nullptr) {
long time = (float)startMS + offset * (endMS - startMS);
float f = 0.0;
auto pf = __audioManager->GetFrameData("", time);
auto pf = __audioManager->GetFrameData(time);
if (pf != nullptr) {
f = ApplyGain(pf->max, GetParameter3());
if (_type == "Inverted Music") {
Expand Down
2 changes: 1 addition & 1 deletion xLights/effects/FireEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void FireEffect::Render(Effect* effect, const SettingsMap& SettingsMap, RenderBu
HeightPct = 10;
if (buffer.GetMedia() != nullptr) {
float f = 0.0;
auto pf = buffer.GetMedia()->GetFrameData(buffer.curPeriod, "");
auto pf = buffer.GetMedia()->GetFrameData(buffer.curPeriod);
if (pf != nullptr) {
f = pf->max;
}
Expand Down
2 changes: 1 addition & 1 deletion xLights/effects/FireworksEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ void FireworksEffect::Render(Effect *effect, const SettingsMap &SettingsMap, Ren
if (useMusic)
{
if (buffer.GetMedia() != nullptr) {
auto pf = buffer.GetMedia()->GetFrameData(buffer.curPeriod, "");
auto pf = buffer.GetMedia()->GetFrameData(buffer.curPeriod);
if (pf != nullptr) {
f = pf->max;
}
Expand Down
2 changes: 1 addition & 1 deletion xLights/effects/LiquidEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ void LiquidEffect::Step(b2World* world, RenderBuffer &buffer, bool enabled[], in
float audioLevel = 0.0001f;
if (buffer.GetMedia() != nullptr)
{
auto pf = buffer.GetMedia()->GetFrameData(buffer.curPeriod, "");
auto pf = buffer.GetMedia()->GetFrameData(buffer.curPeriod);
if (pf != nullptr) {
audioLevel = pf->max;
}
Expand Down
2 changes: 1 addition & 1 deletion xLights/effects/MeteorsEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void MeteorsEffect::Render(Effect *effect, const SettingsMap &SettingsMap, Rende
if (SettingsMap.GetBool("CHECKBOX_Meteors_UseMusic", false)) {
float f = 0.0;
if (buffer.GetMedia() != nullptr) {
auto pf = buffer.GetMedia()->GetFrameData(buffer.curPeriod, "");
auto pf = buffer.GetMedia()->GetFrameData(buffer.curPeriod);
if (pf != nullptr) {
f = pf->max;
}
Expand Down
2 changes: 1 addition & 1 deletion xLights/effects/MusicEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ void MusicEffect::CreateEvents(RenderBuffer& buffer, std::vector<std::list<Music
// go through each frame and extract the data i need
for (int f = buffer.curEffStartPer; f <= buffer.curEffEndPer; ++f)
{
auto pdata = buffer.GetMedia()->GetFrameData(f, "");
auto pdata = buffer.GetMedia()->GetFrameData(f);

if (pdata != nullptr) {
auto pn = pdata->vu.cbegin();
Expand Down
2 changes: 1 addition & 1 deletion xLights/effects/ShaderEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ void ShaderEffect::Render(Effect* eff, const SettingsMap& SettingsMap, RenderBuf

AudioManager* audioManager = buffer.GetMedia();
if (audioManager != nullptr) {
auto fftData = audioManager->GetFrameData(buffer.curPeriod, "");
auto fftData = audioManager->GetFrameData(buffer.curPeriod);
if (fftData) {
std::vector<float> fft128;
if ( _shaderConfig->IsAudioFFTShader() )
Expand Down
2 changes: 1 addition & 1 deletion xLights/effects/ShapeEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ void ShapeEffect::Render(Effect *effect, const SettingsMap &SettingsMap, RenderB
if (timing == "") useTiming = false;
if (useMusic) {
if (buffer.GetMedia() != nullptr) {
auto pf = buffer.GetMedia()->GetFrameData(buffer.curPeriod, "");
auto pf = buffer.GetMedia()->GetFrameData(buffer.curPeriod);
if (pf != nullptr) {
f = pf->max;
}
Expand Down
2 changes: 1 addition & 1 deletion xLights/effects/StrobeEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void StrobeEffect::Render(Effect *effect, const SettingsMap &SettingsMap, Render
if (reactToMusic) {
float f = 0.0;
if (buffer.GetMedia() != nullptr) {
auto pf = buffer.GetMedia()->GetFrameData(buffer.curPeriod, "");
auto pf = buffer.GetMedia()->GetFrameData(buffer.curPeriod);
if (pf != nullptr) {
f = pf->max;
}
Expand Down
4 changes: 2 additions & 2 deletions xLights/effects/TendrilEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ void TendrilEffect::Render(RenderBuffer& buffer, const std::string& movement,
// line movement based on music
float f = 0.1f;
if (buffer.GetMedia() != nullptr) {
auto p = buffer.GetMedia()->GetFrameData(buffer.curPeriod, "");
auto p = buffer.GetMedia()->GetFrameData(buffer.curPeriod);
if (p != nullptr) {
f = p->max;
}
Expand All @@ -767,7 +767,7 @@ void TendrilEffect::Render(RenderBuffer& buffer, const std::string& movement,
}
float f = 0.1f;
if (buffer.GetMedia() != nullptr) {
auto p = buffer.GetMedia()->GetFrameData(buffer.curPeriod, "");
auto p = buffer.GetMedia()->GetFrameData(buffer.curPeriod);
if (p != nullptr) {
f = p->max;
}
Expand Down
Loading

2 comments on commit 60994eb

@derwin12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably enhancement items..
ability to export these in the package sequence, preference to exclude them or perhaps just include the secondary tracks.
ability to use these in the beats and bars creation etc.
(lots of enhancements to look at going forward)

@derwin12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps just insert the subtracks in a section above the line for double height waveform - then the creating of tracks will just work?
image

Please sign in to comment.