tahoma2d/toonz/sources/include/toonz/txshsoundcolumn.h

167 lines
5 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TXSHSOUNDCOLUMN_INCLUDED
#define TXSHSOUNDCOLUMN_INCLUDED
#include "toonz/txshcolumn.h"
#include "toonz/txshcell.h"
#include "tsound.h"
#include <QList>
#include <QTimer>
#undef DVAPI
#undef DVVAR
#ifdef TOONZLIB_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
//=============================================================================
2016-06-15 18:43:10 +12:00
// forward declarations
2016-03-19 06:57:51 +13:00
class TFilePath;
class ColumnLevel;
//=============================================================================
2016-06-15 18:43:10 +12:00
//! The TXshSoundColumn class provides a sound column in xsheet and allows its
//! management through cell concept.
2016-03-19 06:57:51 +13:00
/*!Inherits \b TXshCellColumn. */
//=============================================================================
class DVAPI TXshSoundColumn final : public QObject, public TXshCellColumn {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
PERSIST_DECLARATION(TXshSoundColumn)
TSoundOutputDevice *m_player;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QList<ColumnLevel *> m_levels; // owner
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
/*!Used to menage current playback.*/
TSoundTrackP m_currentPlaySoundTrack;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//! From 0.0 to 1.0
double m_volume;
bool m_isOldVersion;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QTimer m_timer;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TXshSoundColumn();
~TXshSoundColumn();
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
TXshColumn::ColumnType getColumnType() const override;
TXshSoundColumn *getSoundColumn() override { return this; }
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
bool canSetCell(const TXshCell &cell) const override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
TXshColumn *clone() const override;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
/*! Clear column and set src level. */
void assignLevels(const TXshSoundColumn *src);
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void loadData(TIStream &is) override;
void saveData(TOStream &os) override;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
/*! r0 : min row not empty, r1 : max row not empty. Return row count.*/
2016-06-19 20:06:29 +12:00
int getRange(int &r0, int &r1) const override;
2016-06-15 18:43:10 +12:00
/*! Last not empty row - first not empty row. */
2016-06-19 20:06:29 +12:00
int getRowCount() const override;
2016-06-15 18:43:10 +12:00
/*! Return max row not empty. */
2016-06-19 20:06:29 +12:00
int getMaxFrame() const override;
2016-06-15 18:43:10 +12:00
/*! Return min row not empty.*/
2016-06-19 20:06:29 +12:00
int getFirstRow() const override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
const TXshCell &getCell(int row) const override;
void getCells(int row, int rowCount, TXshCell cells[]) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
bool setCell(int row, const TXshCell &cell) override;
2016-06-15 18:43:10 +12:00
/*! Return false if cannot set cells.*/
2016-06-19 20:06:29 +12:00
bool setCells(int row, int rowCount, const TXshCell cells[]) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void insertEmptyCells(int row, int rowCount) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void clearCells(int row, int rowCount) override;
void removeCells(int row, int rowCount) override;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
/*! Check if frames from \b row to \b row+rowCount are in sequence and
* collapse level if it is true. */
void updateCells(int row, int rowCount);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
/*! Modify range of level sound in row. Return new range value of the level in
row.
N.B. Row must be the first or last cell of a sound level. */
int modifyCellRange(int row, int delta, bool modifyStartValue);
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
bool isCellEmpty(int row) const override;
2016-06-15 18:43:10 +12:00
/*! r0 : min row not empty of level in row, r1 : max row not empty of level in
row.
Return true if level range is not empty.*/
2016-06-19 20:06:29 +12:00
bool getLevelRange(int row, int &r0, int &r1) const override;
2016-06-15 18:43:10 +12:00
/*! r0 : min possible (without offset) row of level in row, r1 : max possible
(without offset) row of level in row.
Return true if level range is not empty.*/
bool getLevelRangeWithoutOffset(int row, int &r0, int &r1) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
/*! Only debug. */
2016-06-19 20:06:29 +12:00
void checkColumn() const override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void setXsheet(TXsheet *xsheet) override;
2016-06-15 18:43:10 +12:00
void setFrameRate(double fps);
void updateFrameRate(double fps);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//! From 0.0 to 1.0
void setVolume(double value);
double getVolume() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TSoundTrackP getCurrentPlaySoundTruck() { return m_currentPlaySoundTrack; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//! s0 and s1 are samples
void play(TSoundTrackP soundtrack, int s0, int s1, bool loop);
/*! Play the whole soundSequence, currentFrame it is used to compute an offset
when the user play a single level and hence the audio behind..*/
void play(ColumnLevel *ss, int currentFrame);
void play(int currentFrame = 0);
void stop();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isPlaying() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void scrub(int fromFrame, int toFrame);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TSoundTrackP getOverallSoundTrack(
int fromFrame = -1, int toFram = -1, double fps = -1,
TSoundTrackFormat format = TSoundTrackFormat());
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TSoundTrackP mixingTogether(const std::vector<TXshSoundColumn *> &vect,
int fromFrame = -1, int toFram = -1,
double fps = -1);
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
bool setCell(int row, const TXshCell &cell, bool updateSequence);
void removeCells(int row, int rowCount, bool shift);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setCellInEmptyFrame(int row, const TXshCell &cell);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
/*! If index == -1 insert soundColumnLevel at last and than order
* soundColumnLevel by startFrame. */
void insertColumnLevel(ColumnLevel *columnLevel, int index = -1);
void removeColumnLevel(ColumnLevel *columnLevel);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
ColumnLevel *getColumnLevelByFrame(int frame) const;
ColumnLevel *getColumnLevel(int index);
int getColumnLevelIndex(ColumnLevel *ss) const;
void clear();
2016-03-19 06:57:51 +13:00
protected slots:
2016-06-15 18:43:10 +12:00
void onTimerOut();
2016-03-19 06:57:51 +13:00
};
2016-04-15 17:11:23 +12:00
#ifdef _WIN32
2016-03-19 06:57:51 +13:00
template class DV_EXPORT_API TSmartPointerT<TXshSoundColumn>;
#endif
typedef TSmartPointerT<TXshSoundColumn> TXshSoundColumnP;
#endif