File: PlayState.cpp

package info (click to toggle)
libopenmpt 0.8.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,844 kB
  • sloc: cpp: 129,441; sh: 4,695; ansic: 1,107; makefile: 712
file content (76 lines) | stat: -rw-r--r-- 2,294 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * PlayState.cpp
 * -------------
 * Purpose: This class represents all of the playback state of a module.
 * Notes  : (currently none)
 * Authors: OpenMPT Devs
 * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
 */


#include "stdafx.h"
#include "PlayState.h"
#include "MIDIMacros.h"
#include "Mixer.h"
#include "Sndfile.h"


OPENMPT_NAMESPACE_BEGIN


PlayState::PlayState()
{
	Chn.fill({});
	m_midiMacroScratchSpace.reserve(kMacroLength);  // Note: If macros ever become variable-length, the scratch space needs to be at least one byte longer than the longest macro in the file for end-of-SysEx insertion to stay allocation-free in the mixer!
}


void PlayState::ResetGlobalVolumeRamping() noexcept
{
	m_lHighResRampingGlobalVolume = m_nGlobalVolume << VOLUMERAMPPRECISION;
	m_nGlobalVolumeDestination = m_nGlobalVolume;
	m_nSamplesToGlobalVolRampDest = 0;
	m_nGlobalVolumeRampAmount = 0;
}


void PlayState::UpdateTimeSignature(const CSoundFile &sndFile) noexcept
{
	if(!sndFile.Patterns.IsValidIndex(m_nPattern) || !sndFile.Patterns[m_nPattern].GetOverrideSignature())
	{
		m_nCurrentRowsPerBeat = sndFile.m_nDefaultRowsPerBeat;
		m_nCurrentRowsPerMeasure = sndFile.m_nDefaultRowsPerMeasure;
	} else
	{
		m_nCurrentRowsPerBeat = sndFile.Patterns[m_nPattern].GetRowsPerBeat();
		m_nCurrentRowsPerMeasure = sndFile.Patterns[m_nPattern].GetRowsPerMeasure();
	}
}


void PlayState::UpdatePPQ(bool patternTransition) noexcept
{
	ROWINDEX rpm = m_nCurrentRowsPerMeasure ? m_nCurrentRowsPerMeasure : DEFAULT_ROWS_PER_MEASURE;
	ROWINDEX rpb = m_nCurrentRowsPerBeat ? m_nCurrentRowsPerBeat : DEFAULT_ROWS_PER_BEAT;
	if(m_lTotalSampleCount > 0 && (patternTransition || !(m_nRow % rpm)))
	{
		// Pattern end = end of measure, so round up PPQ to the next full measure
		m_ppqPosBeat += (rpm + (rpb - 1)) / rpb;
		m_ppqPosFract = 0;
	}
}


mpt::span<ModChannel> PlayState::PatternChannels(const CSoundFile &sndFile) noexcept
{
	return mpt::as_span(Chn).subspan(0, std::min(Chn.size(), static_cast<size_t>(sndFile.GetNumChannels())));
}


mpt::span<ModChannel> PlayState::BackgroundChannels(const CSoundFile &sndFile) noexcept
{
	return mpt::as_span(Chn).subspan(std::min(Chn.size(), static_cast<size_t>(sndFile.GetNumChannels())));
}


OPENMPT_NAMESPACE_END