Skip to content

Commit

Permalink
added the missing files and fixed 2 small bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
stohrendorf committed Jun 26, 2011
1 parent 33cd11a commit 86907fd
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/stream/iarchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ class IArchive {
bool isSaving() const ;
// the pragma is used to get rid of the annoying
// warning: ‘IArchive& IArchive::operator%(T&)’ should return by value [-Weffc++]
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
//! @bug "#pragma #pragma GCC diagnostic [push|pop]" is only available in GCC 4.6+
// #pragma GCC diagnostic push
// #pragma GCC diagnostic ignored "-Weffc++"
/**
* @brief Serialization operator
* @tparam T Data type
Expand All @@ -76,7 +77,7 @@ class IArchive {
}
return *this;
}
#pragma GCC diagnostic pop
// #pragma GCC diagnostic pop
/**
* @brief Serialization operator for arrays
* @tparam T Data type
Expand Down
173 changes: 173 additions & 0 deletions src/xmmod/xmcell.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/*
PeePeePlayer - an old-fashioned module player
Copyright (C) 2011 Steffen Ohrendorf <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* @ingroup XmModule
* @{
*/

#include "xmcell.h"

#include "xmbase.h"
#include "genmod/genbase.h"
#include "stream/iarchive.h"

namespace ppp {
namespace xm {

XmCell::XmCell() : GenCell(), m_note(0), m_instr(0), m_volume(0), m_effect(Effect::None), m_effectValue(0) {
}

XmCell::~XmCell() = default;

bool XmCell::load(BinStream& str) {
uint8_t data;
str.read(&data);
if((data & 0x80) == 0) {
m_note = data;
str.read(&m_instr).read(&m_volume).read(reinterpret_cast<uint8_t*>(&m_effect)).read(&m_effectValue);
return !str.fail();
}
if(data & 0x01)
str.read(&m_note);
if(data & 0x02)
str.read(&m_instr);
if(data & 0x04)
str.read(&m_volume);
if(data & 0x08)
str.read(reinterpret_cast<uint8_t*>(&m_effect));
if(data & 0x10)
str.read(&m_effectValue);
return !str.fail();
}

void XmCell::clear() {
m_note = 0;
m_instr = 0xff;
m_volume = 0;
m_effect = Effect::None;
m_effectValue = 0;
}

std::string XmCell::fxString() const {
if(m_effect == Effect::None) {
return "...";
}
else if(static_cast<uint8_t>(m_effect) <= 0x0f) {
return stringf("%1X%.2X", static_cast<uint8_t>(m_effect), m_effectValue);
}
else if(static_cast<uint8_t>(m_effect) <= 0x21) {
return stringf("%c%.2X", static_cast<uint8_t>(m_effect) - 0x0f + 'F', m_effectValue);
}
else {
return stringf("?%.2X", m_effectValue);
}
}

std::string XmCell::noteString() const {
if(m_note == 0) {
return "...";
}
else if(m_note == KeyOffNote) {
return "===";
}
else if(m_note < KeyOffNote) {
return stringf("%s%d", NoteNames.at((m_note - 1) % 12), (m_note - 1) / 12);
}
else {
return "???";
}
}

std::string XmCell::trackerString() const {
/* if(!isActive())
return "... ...";*/
std::string xmsg = noteString();
if(m_instr == 0) {
xmsg += " ";
}
else {
xmsg += stringf(" %2X ", m_instr);
}
/*
VfxVolSlideDown = 6,
VfxVolSlideUp = 7,
VfxFineVolSlideDown = 8,
VfxFineVolSlideUp = 9,
VfxSetVibSpeed = 0xa,
VfxVibrato = 0xb,
VfxSetPanning = 0xc,
VfxPanSlideLeft = 0xd,
VfxPanSlideRight = 0xe,
VfxPorta = 0xf
*/
static const char vfxChars[] = "-+DUSVPLRM";
switch(highNibble(m_volume)) {
case 0:
xmsg += " ";
break;
case 1:
case 2:
case 3:
case 4:
case 5:
xmsg += stringf("%2d ", m_volume - 0x10);
break;
default:
xmsg += stringf("%c%X ", vfxChars[highNibble(m_volume) - 6], lowNibble(m_volume));
break;
}
return xmsg + fxString();
}

uint8_t XmCell::note() const {
return m_note;
}

uint8_t XmCell::instrument() const {
return m_instr;
}

uint8_t XmCell::volume() const {
return m_volume;
}

Effect XmCell::effect() const {
return m_effect;
}

uint8_t XmCell::effectValue() const {
return m_effectValue;
}

IArchive& XmCell::serialize(IArchive* data) {
*data
% m_note
% m_instr
% m_volume
% *reinterpret_cast<uint8_t*>(&m_effect)
% m_effectValue;
return *data;
}

}
}

/**
* @}
*/
104 changes: 104 additions & 0 deletions src/xmmod/xmcell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
PeePeePlayer - an old-fashioned module player
Copyright (C) 2011 Steffen Ohrendorf <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef XMCELL_H
#define XMCELL_H

/**
* @ingroup XmModule
* @{
*/

#include "genmod/gencell.h"
#include "xmbase.h"
#include "stream/binstream.h"

namespace ppp {
namespace xm {

/**
* @class XmCell
* @brief Cell of a pattern
*/
class XmCell : public GenCell {
public:
typedef std::shared_ptr<XmCell> Ptr; //!< @brief Class pointer
typedef std::vector<Ptr> Vector; //!< @brief Vector of class pointers
private:
uint8_t m_note; //!< @brief Note value
uint8_t m_instr; //!< @brief Instrument value
uint8_t m_volume; //!< @brief Volume value
Effect m_effect; //!< @brief Effect
uint8_t m_effectValue; //!< @brief Effect value
public:
XmCell();
virtual ~XmCell();
/**
* @brief Load the cell data from a stream
* @param[in] str The stream to load from
* @return @c true on success
*/
bool load(BinStream& str);
virtual void clear();
virtual std::string trackerString() const;
/**
* @brief Get the note string, e.g. in the form "C#3"
* @return The note string
*/
std::string noteString() const;
/**
* @brief Get the string representation of the effect/value columns
* @return String in the form of e.g. "R0A"
*/
std::string fxString() const;
/**
* @brief Get the note value
* @return m_note
*/
uint8_t note() const;
/**
* @brief Get the instrument value
* @return m_instrument
*/
uint8_t instrument() const;
/**
* @brief Get the volume value
* @return m_volume
*/
uint8_t volume() const;
/**
* @brief Get the effect
* @return m_effect
*/
Effect effect() const;
/**
* @brief Get the effect value
* @return m_effectValue
*/
uint8_t effectValue() const;
virtual IArchive& serialize(IArchive* data);
};

}
}

/**
* @}
*/

#endif
13 changes: 7 additions & 6 deletions src/xmmod/xmchannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,8 @@ void XmChannel::update(const ppp::xm::XmCell::Ptr& cell) {
m_instrumentIndex = m_currentCell.instrument();
}
if(m_currentCell.effect() == Effect::Extended) {
if(highNibble(m_currentCell.effectValue()) == EfxNoteDelay) {
if(lowNibble(m_currentCell.effectValue()) != 0) {
return;
}
if(highNibble(m_currentCell.effectValue()) == EfxNoteDelay && lowNibble(m_currentCell.effectValue()) != 0) {
return;
}
else if(highNibble(m_currentCell.effectValue()) == EfxRetrigger && lowNibble(m_currentCell.effectValue()) == 0) {
if(m_currentCell.note() != KeyOffNote) {
Expand All @@ -264,13 +262,11 @@ void XmChannel::update(const ppp::xm::XmCell::Ptr& cell) {
if(lowNibble(m_currentCell.volume()) != 0) {
m_portaSpeed = lowNibble(m_currentCell.volume()) << 4;
}
calculatePortaTarget(m_currentCell.note());
}
else if(m_currentCell.effect() == Effect::Porta) {
if(m_currentCell.effectValue() != 0) {
m_portaSpeed = m_currentCell.effectValue() << 2;
}
calculatePortaTarget(m_currentCell.note());
}
else if(m_currentCell.effect() != Effect::PortaVolSlide && m_currentCell.note() != 0) {
if(m_currentCell.note() == KeyOffNote) {
Expand All @@ -282,6 +278,11 @@ void XmChannel::update(const ppp::xm::XmCell::Ptr& cell) {
doKeyOn();
}
}

if(m_currentCell.note()!=0 && m_currentCell.note()!=KeyOffNote) {
calculatePortaTarget(m_currentCell.note());
}

m_fxString = " ";
switch(highNibble(m_currentCell.volume())) {
case 0x01:
Expand Down
2 changes: 1 addition & 1 deletion src/xmmod/xmenvelopeprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class XmEnvelopeProcessor : public ISerializable {
* @return @c true if @c a&b is not 0
*/
inline bool operator&(const XmEnvelopeProcessor::EnvelopeFlags& a, const XmEnvelopeProcessor::EnvelopeFlags& b) {
return static_cast<uint8_t>(a) & static_cast<uint8_t>(b);
return (static_cast<uint8_t>(a) & static_cast<uint8_t>(b)) != 0;
}

}
Expand Down

0 comments on commit 86907fd

Please sign in to comment.