Jeremy Bullock f15907
#pragma once
Jeremy Bullock f15907
Jeremy Bullock f15907
#ifndef STOPMOTION_H
Jeremy Bullock f15907
#define STOPMOTION_H
Jeremy Bullock f15907
shun-iwasawa 31accf
#ifdef WITH_CANON
Jeremy Bullock f15907
// Canon Includes
Jeremy Bullock f15907
#include "EDSDK.h"
Jeremy Bullock f15907
#include "EDSDKErrors.h"
Jeremy Bullock f15907
#include "EDSDKTypes.h"
shun-iwasawa 31accf
#endif
shun-iwasawa 31accf
shun-iwasawa 31accf
#if defined(x64)
Jeremy Bullock f15907
#include "turbojpeg.h"
shun-iwasawa 31accf
#endif
Jeremy Bullock f15907
Jeremy Bullock f15907
// Toonz Includes
Jeremy Bullock f15907
#include "traster.h"
Jeremy Bullock f15907
#include "toonzqt/gutil.h"
Jeremy Bullock f15907
#include "toonzqt/dvdialog.h"
Jeremy Bullock f15907
shun-iwasawa 31accf
#include "webcam.h"
shun-iwasawa 31accf
#include "jpgconverter.h"
shun-iwasawa 31accf
#include "canon.h"
shun-iwasawa 31accf
#include "stopmotionserial.h"
shun-iwasawa 31accf
#include "stopmotionlight.h"
shun-iwasawa 31accf
shun-iwasawa 31accf
#include "toonz/txshsimplelevel.h"
shun-iwasawa 31accf
Jeremy Bullock f15907
#include <qobject></qobject>
shun-iwasawa 31accf
#include <qthread></qthread>
justburner d63640
#include <qsound></qsound>
Jeremy Bullock f15907
Jeremy Bullock f15907
class QCamera;
Jeremy Bullock f15907
class QCameraInfo;
Jeremy Bullock f15907
class QTimer;
Jeremy Bullock f15907
Jeremy Bullock f15907
enum ASPECT_RATIO { FOUR_THREE = 0, THREE_TWO, SIXTEEN_NINE, OTHER_RATIO };
Jeremy Bullock f15907
Jeremy Bullock f15907
class StopMotion : public QObject {  // Singleton
Jeremy Bullock f15907
  Q_OBJECT
Jeremy Bullock f15907
Jeremy Bullock f15907
public:
Jeremy Bullock f15907
  static StopMotion* instance() {
Jeremy Bullock f15907
    static StopMotion _instance;
Jeremy Bullock f15907
    return &_instance;
Jeremy Bullock f15907
  };
Jeremy Bullock f15907
Jeremy Bullock f15907
private:
Jeremy Bullock f15907
  StopMotion();
Jeremy Bullock f15907
  ~StopMotion();
Jeremy Bullock f15907
shun-iwasawa 31accf
  // file stuff
Jeremy Bullock f15907
  int m_frameNumber          = 1;
shun-iwasawa 31accf
  int m_xSheetFrameNumber    = 1;
Jeremy Bullock f15907
  QString m_levelName        = "";
Jeremy Bullock f15907
  QString m_fileType         = "jpg";
Jeremy Bullock f15907
  QString m_filePath         = "+extras";
Jeremy Bullock f15907
  QString m_frameInfoText    = "";
Jeremy Bullock f15907
  QString m_infoColorName    = "";
Jeremy Bullock f15907
  QString m_frameInfoToolTip = "";
shun-iwasawa 31accf
shun-iwasawa 31accf
  // options
shun-iwasawa 31accf
  int m_opacity     = 255.0;
shun-iwasawa 31accf
  int m_subsampling = 1;
Jeremy Bullock f15907
  QSize m_allowedCameraSize;
Jeremy Bullock f15907
  bool m_useNumpadShortcuts      = false;
Jeremy Bullock f15907
  bool m_numpadForStyleSwitching = true;
Jeremy Bullock f15907
  bool m_turnOnRewind            = false;
Jeremy Bullock f15907
Jeremy Bullock f15907
  std::map<std::string, qaction*=""> m_oldActionMap;</std::string,>
shun-iwasawa 31accf
  std::map<int, traster32p=""> m_liveViewImageMap;</int,>
Jeremy Bullock f15907
justburner d63640
  bool m_playCaptureSound = false;
justburner d63640
  QSound* m_camSnapSound  = 0;
justburner d63640
Jeremy Bullock f15907
public:
Jeremy Bullock f15907
  enum LiveViewStatus {
Jeremy Bullock f15907
    LiveViewClosed = 0,
Jeremy Bullock f15907
    LiveViewStarting,
Jeremy Bullock f15907
    LiveViewOpen,
Jeremy Bullock f15907
    LiveViewPaused
Jeremy Bullock f15907
  };
Jeremy Bullock f15907
shun-iwasawa 31accf
  Webcam* m_webcam;
shun-iwasawa 31accf
  Canon* m_canon;
shun-iwasawa 31accf
  StopMotionSerial* m_serial;
shun-iwasawa 31accf
  StopMotionLight* m_light;
shun-iwasawa 31accf
shun-iwasawa 31accf
  bool m_usingWebcam       = false;
shun-iwasawa 31accf
  bool m_placeOnXSheet     = true;
shun-iwasawa 31accf
  bool m_alwaysLiveView    = false;
shun-iwasawa 31accf
  bool m_userCalledPause   = false;
shun-iwasawa 31accf
  bool m_drawBeneathLevels = true;
shun-iwasawa 31accf
  bool m_isTimeLapse       = false;
justburner d63640
  int m_reviewTimeDSec     = 20;
Jeremy Bullock f15907
  QString m_tempFile;
shun-iwasawa 31accf
  TXshSimpleLevel* m_sl;
shun-iwasawa 31accf
shun-iwasawa 31accf
  // timers
Jeremy Bullock f15907
  QTimer* m_timer;
justburner d63640
  int m_intervalDSec     = 100;
shun-iwasawa 31accf
  bool m_intervalStarted = false;
shun-iwasawa 31accf
  QTimer* m_reviewTimer;
shun-iwasawa 31accf
  QTimer *m_intervalTimer, *m_countdownTimer, *m_webcamOverlayTimer;
shun-iwasawa 31accf
shun-iwasawa 31accf
  // live view and images
shun-iwasawa 31accf
  int m_liveViewStatus = LiveViewClosed;
shun-iwasawa 31accf
  bool m_hasLiveViewImage, m_hasLineUpImage, m_showLineUpImage;
shun-iwasawa 31accf
  bool m_alwaysUseLiveViewImages = false;
Jeremy Bullock f15907
  TRaster32P m_liveViewImage, m_newImage, m_lineUpImage;
Jeremy Bullock f15907
  TDimension m_liveViewImageDimensions = TDimension(0, 0);
Jeremy Bullock f15907
  TDimension m_fullImageDimensions     = TDimension(0, 0);
Jeremy Bullock f15907
  TPointD m_liveViewDpi                = TPointD(0.0, 0.0);
Jeremy Bullock f15907
  TPointD m_fullImageDpi               = TPointD(0.0, 0.0);
Jeremy Bullock f15907
shun-iwasawa 31accf
  // files and frames
Jeremy Bullock f15907
  void setXSheetFrameNumber(int frameNumber);
Jeremy Bullock f15907
  int getXSheetFrameNumber() { return m_xSheetFrameNumber; }
Jeremy Bullock f15907
  void setFrameNumber(int frameNumber);
Jeremy Bullock f15907
  int getFrameNumber() { return m_frameNumber; }
Jeremy Bullock f15907
  void setLevelName(QString levelName);
Jeremy Bullock f15907
  QString getLevelName() { return m_levelName; }
Jeremy Bullock f15907
  void setFileType(QString fileType);
Jeremy Bullock f15907
  QString getFileType() { return m_fileType; }
Jeremy Bullock f15907
  void setFilePath(QString filePath);
Jeremy Bullock f15907
  QString getFilePath() { return m_filePath; }
Jeremy Bullock f15907
  void updateLevelNameAndFrame(std::wstring levelName);
Jeremy Bullock f15907
  void setToNextNewLevel();
Jeremy Bullock f15907
  void nextFrame();
Jeremy Bullock f15907
  void previousFrame();
Jeremy Bullock f15907
  void lastFrame();
Jeremy Bullock f15907
  void nextName();
Jeremy Bullock f15907
  void previousName();
shun-iwasawa 31accf
  void refreshFrameInfo();
Jeremy Bullock f15907
  QString getFrameInfoText() { return m_frameInfoText; }
Jeremy Bullock f15907
  QString getInfoColorName() { return m_infoColorName; }
Jeremy Bullock f15907
  QString getFrameInfoToolTip() { return m_frameInfoToolTip; }
Jeremy Bullock f15907
shun-iwasawa 31accf
  // cameras
shun-iwasawa 31accf
  void setWebcamResolution(QString resolution);
Jeremy Bullock f15907
  std::string getTEnvCameraName();
Jeremy Bullock f15907
  void setTEnvCameraName(std::string name);
Jeremy Bullock f15907
  std::string getTEnvCameraResolution();
Jeremy Bullock f15907
  void setTEnvCameraResolution(std::string resolution);
shun-iwasawa 31accf
  void disconnectAllCameras();
shun-iwasawa 31accf
  void changeCameras(int index);
shun-iwasawa 31accf
  void refreshCameraList();
shun-iwasawa 31accf
shun-iwasawa 31accf
  // commands
shun-iwasawa 31accf
  void jumpToCameraFrame();
shun-iwasawa 31accf
  void removeStopMotionFrame();
Jeremy Bullock f15907
shun-iwasawa 31accf
  // live view and images
shun-iwasawa 31accf
  bool toggleLiveView();
shun-iwasawa 31accf
  void pauseLiveView();
Jeremy Bullock f15907
  bool loadLineUpImage();
shun-iwasawa 31accf
  bool loadLiveViewImage(int row, TRaster32P& image);
shun-iwasawa 31accf
  void setLiveViewImage();
shun-iwasawa 31accf
  void captureImage();
shun-iwasawa 31accf
  void captureWebcamImage();
shun-iwasawa 31accf
  void captureDslrImage();
shun-iwasawa 31accf
  void postImportProcess();
shun-iwasawa 31accf
  void toggleAlwaysUseLiveViewImages();
shun-iwasawa 31accf
  bool buildLiveViewMap(TXshSimpleLevel* sl);
shun-iwasawa 31accf
shun-iwasawa 31accf
  // time lapse
shun-iwasawa 31accf
  void toggleInterval(bool on);
shun-iwasawa 31accf
  void startInterval();
shun-iwasawa 31accf
  void stopInterval();
justburner d63640
  void setIntervalDSec(int value);
justburner d63640
  int getIntervalDSec() { return m_intervalDSec; };
shun-iwasawa 31accf
  void restartInterval();
shun-iwasawa 31accf
shun-iwasawa 31accf
  // options
shun-iwasawa 31accf
  void raiseOpacity();
shun-iwasawa 31accf
  void lowerOpacity();
shun-iwasawa 31accf
  void setOpacity(int opacity);
shun-iwasawa 31accf
  int getOpacity() { return m_opacity; }
shun-iwasawa 31accf
  void setAlwaysLiveView(bool on);
shun-iwasawa 31accf
  bool getAlwaysLiveView() { return m_alwaysLiveView; }
shun-iwasawa 31accf
  void setPlaceOnXSheet(bool on);
shun-iwasawa 31accf
  bool getPlaceOnXSheet() { return m_placeOnXSheet; }
shun-iwasawa 31accf
  void setUseNumpadShortcuts(bool on);
shun-iwasawa 31accf
  bool getUseNumpadShortcuts() { return m_useNumpadShortcuts; }
shun-iwasawa 31accf
  void toggleNumpadShortcuts(bool on);
shun-iwasawa 31accf
  void toggleNumpadForFocusCheck(bool on);
shun-iwasawa 31accf
  void setDrawBeneathLevels(bool on);
justburner d63640
  void setReviewTimeDSec(int timeDSec);
justburner d63640
  int getReviewTimeDSec() { return m_reviewTimeDSec; }
shun-iwasawa 31accf
  void getSubsampling();
shun-iwasawa 31accf
  void setSubsampling();
shun-iwasawa 31accf
  int getSubsamplingValue() { return m_subsampling; }
shun-iwasawa 31accf
  void setSubsamplingValue(int subsampling);
justburner d63640
  void setPlayCaptureSound(bool on);
justburner d63640
  bool getPlayCaptureSound() { return m_playCaptureSound; }
shun-iwasawa 31accf
shun-iwasawa 31accf
  // saving and loading
shun-iwasawa 31accf
  void saveXmlFile();
shun-iwasawa 31accf
  bool loadXmlFile();
shun-iwasawa 31accf
  bool exportImageSequence();
Jeremy Bullock f15907
Jeremy Bullock f15907
public slots:
shun-iwasawa 31accf
  // timers
Jeremy Bullock f15907
  void onTimeout();
Jeremy Bullock f15907
  void onReviewTimeout();
shun-iwasawa 31accf
  void onIntervalCaptureTimerTimeout();
shun-iwasawa 31accf
  void captureWebcamOnTimeout();
Jeremy Bullock f15907
  void update();
Jeremy Bullock f15907
  bool importImage();
Jeremy Bullock f15907
  void onSceneSwitched();
Jeremy Bullock f15907
  void onPlaybackChanged();
shun-iwasawa 31accf
  void onCanonCameraChanged(QString);
Jeremy Bullock f15907
Jeremy Bullock f15907
signals:
shun-iwasawa 31accf
  // camera stuff
shun-iwasawa 31accf
  void cameraChanged(QString);
Jeremy Bullock f15907
  void newCameraSelected(int, bool);
Jeremy Bullock f15907
  void webcamResolutionsChanged();
Jeremy Bullock f15907
  void newWebcamResolutionSelected(int);
shun-iwasawa 31accf
  void updateCameraList(QString);
Jeremy Bullock f15907
shun-iwasawa 31accf
  // live view and images
shun-iwasawa 31accf
  void newLiveViewImageReady();
shun-iwasawa 31accf
  void liveViewStopped();
shun-iwasawa 31accf
  void newImageReady();
shun-iwasawa 31accf
  void liveViewChanged(bool);
shun-iwasawa 31accf
  void liveViewOnAllFramesSignal(bool);
Jeremy Bullock f15907
  void newDimensions();
shun-iwasawa 31accf
  void alwaysUseLiveViewImagesToggled(bool);
shun-iwasawa 31accf
shun-iwasawa 31accf
  // file stuff
Jeremy Bullock f15907
  void filePathChanged(QString);
Jeremy Bullock f15907
  void levelNameChanged(QString);
Jeremy Bullock f15907
  void fileTypeChanged(QString);
Jeremy Bullock f15907
  void frameNumberChanged(int);
Jeremy Bullock f15907
  void frameInfoTextChanged(QString);
shun-iwasawa 31accf
  void xSheetFrameNumberChanged(int);
shun-iwasawa 31accf
shun-iwasawa 31accf
  // options
shun-iwasawa 31accf
  void optionsChanged();
shun-iwasawa 31accf
  void subsamplingChanged(int);
Jeremy Bullock f15907
  void opacityChanged(int);
Jeremy Bullock f15907
  void placeOnXSheetSignal(bool);
Jeremy Bullock f15907
  void useNumpadSignal(bool);
shun-iwasawa 31accf
  void drawBeneathLevelsSignal(bool);
Jeremy Bullock f15907
  void reviewTimeChangedSignal(int);
justburner d63640
  void playCaptureSignal(bool);
shun-iwasawa 31accf
shun-iwasawa 31accf
  // time lapse
shun-iwasawa 31accf
  void intervalToggled(bool);
shun-iwasawa 31accf
  void intervalStarted();
shun-iwasawa 31accf
  void intervalStopped();
shun-iwasawa 31accf
  void intervalAmountChanged(int);
Jeremy Bullock f15907
};
Jeremy Bullock f15907
Jeremy Bullock f15907
#endif  // STOPMOTION_H