Blame view

Shot.cpp 2.23 KB
3f2992b2c   bostx   V1.0
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  #include <QJsonArray>
  
  #include "Shot.h"
  
  #include <QDebug>
  
  Shot::Shot(Segment *parentSegment)
    : Segment(parentSegment)
  {
  }
  
  Shot::Shot(qint64 position, TransitionType transitionType, Segment *parentSegment, Segment::Source source)
    : Segment(position, parentSegment, source),
      m_transitionType(transitionType),
      m_end(-1)
  {
    m_camera = new QVector<int>(2);
    for (int i(0); i < m_camera->size(); i++)
      m_camera->replace(i, -1);
  }
  
  Shot::~Shot()
  {
  }
  
  void Shot::read(const QJsonObject &json)
  {
    m_source = static_cast<Source>(json["source"].toInt());
    m_transitionType = static_cast<TransitionType>(json["trans"].toInt());
    m_end = -1;
  
    m_camera = new QVector<int>(2);
  
    QJsonArray camArray = json["cam"].toArray();
    for (int i(0); i < m_camera->size(); i++)
      m_camera->replace(i, camArray[i].toInt());
  
    Segment::read(json);
  }
  
  void Shot::write(QJsonObject &json) const
  {
    json["source"] = m_source;
    json["trans"] = m_transitionType;
  
    QJsonArray camArray;
    for (int i = 0; i < m_camera->size(); i++)
      camArray.append(m_camera->at(i));
  
    json["cam"] = camArray;
  
     Segment::write(json);
  }
  
  QString Shot::display() const
  {
    return "Shot " + QString::number(row()+1);
  }
  
  ///////////////
  // modifiers //
  ///////////////
  
  void Shot::setEnd(qint64 end)
  {
    m_end = end;
  }
  
  void Shot::setCamera(int nCamera, Segment::Source source)
  {
    m_camera->replace(source, nCamera);
  }
  
  ///////////////
  // accessors //
  ///////////////
  
  int Shot::getNumber() const
  {
    return row() + 1;
  }
  
  qint64 Shot::getEnd()
  {
    return m_end;
  }
  
  int Shot::getCamera(Segment::Source source) const
  {
    return m_camera->value(source);
  }
  
  QString Shot::getLabel() const
  {
    int nCamera = m_camera->value(Segment::Manual);
  
    if (nCamera != -1)
      return "C" + QString::number(nCamera);
    else
      return QString();
  }
  
  QMap<QString, int> Shot::getSpeakerList(VideoFrame::SpeakerSource source)
  {
    QMap<QString, int> speakerList;
    QString speakerLabel;
    VideoFrame *frame;
    int n;
    
    for (int i(0); i < childCount(); i++) {
      speakerLabel = (frame = dynamic_cast<VideoFrame *>(child(i)))->getSpeaker(source);
      
      if (!speakerLabel.isEmpty()) {
        n = speakerList.value(speakerLabel);
        speakerList.insert(speakerLabel, ++n);
      }
    }
  
    return speakerList;
  }