Skip to content

Commit

Permalink
allow song to play its own preview and give lua access (experimental)
Browse files Browse the repository at this point in the history
borp
  • Loading branch information
MinaciousGrace committed Nov 25, 2018
1 parent f099fe7 commit 0c976a2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ local function toggleNoteField()
return end

if song then
song:Borp()
if mcbootlarder:GetVisible() then
mcbootlarder:visible(false)
mcbootlarder:GetChild("NoteField"):visible(false)
Expand Down
27 changes: 24 additions & 3 deletions src/Song.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "global.h"
#include "global.h"
#include "FontCharAliases.h"
#include "GameManager.h"
#include "RageLog.h"
Expand Down Expand Up @@ -34,6 +34,7 @@
#include "LyricsLoader.h"
#include "ActorUtil.h"
#include "CommonMetrics.h"
#include "GameSoundManager.h"

#include "GameState.h"
#include <cfloat>
Expand Down Expand Up @@ -2047,6 +2048,21 @@ Song::IsMarathon() const
return m_fMusicLengthSeconds >= g_fMarathonVerSongSeconds;
}

void
Song::Borp()
{
GameSoundManager::PlayMusicParams PlayParams;
PlayParams.sFile = m_sMusicFile;
PlayParams.pTiming = &this->m_SongTiming;
PlayParams.bForceLoop = true;
PlayParams.fStartSecond = m_fMusicSampleStartSeconds;
PlayParams.fLengthSeconds = GetLastSecond() + 2.f;
PlayParams.fFadeOutLengthSeconds = 1.f;
PlayParams.bAlignBeat = true;
PlayParams.bApplyMusicRate = true;
SOUND->PlayMusic(PlayParams);
}

// lua start
#include "LuaBinding.h"

Expand Down Expand Up @@ -2468,13 +2484,17 @@ class LunaSong : public Luna<Song>
p->ReloadFromSongDir();
COMMON_RETURN_SELF;
}

static int GetOrTryAtLeastToGetSimfileAuthor(T* p, lua_State* L)
{
lua_pushstring(L, p->GetOrTryAtLeastToGetSimfileAuthor());
return 1;
}

static int Borp(T* p, lua_State* L)
{
p->Borp();
return 0;
}

LunaSong()
{
ADD_METHOD(GetDisplayFullTitle);
Expand Down Expand Up @@ -2543,6 +2563,7 @@ class LunaSong : public Luna<Song>
ADD_METHOD(GetPreviewVidPath);
ADD_METHOD(GetPreviewMusicPath);
ADD_METHOD(ReloadFromSongDir);
ADD_METHOD(Borp);
}
};

Expand Down
5 changes: 4 additions & 1 deletion src/Song.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef SONG_H
#ifndef SONG_H
#define SONG_H

#include "Difficulty.h"
Expand Down Expand Up @@ -438,6 +438,9 @@ class Song
bool IsLong() const;
bool IsMarathon() const;

// plays music for chart preview and is available to lua -mina
void Borp();

bool SongCompleteForStyle(const Style* st) const;
bool HasStepsType(StepsType st) const;
bool HasStepsTypeAndDifficulty(StepsType st, Difficulty dc) const;
Expand Down

0 comments on commit 0c976a2

Please sign in to comment.