]> git.sesse.net Git - nageru/blobdiff - futatabi/clip_list.cpp
Call the done callback only when the entire playlist is done. Simplifies a fair amoun...
[nageru] / futatabi / clip_list.cpp
index 0a3faf01a09e517e4ac49db957ed9b96fac97c2f..0bb73ae404e367bc8c52d106928a4e435749c044 100644 (file)
@@ -131,6 +131,7 @@ QVariant PlayList::data(const QModelIndex &parent, int role) const
                case Column::OUT:
                case Column::DURATION:
                case Column::FADE_TIME:
+               case Column::SPEED:
                        return Qt::AlignRight + Qt::AlignVCenter;
                case Column::CAMERA:
                        return Qt::AlignCenter;
@@ -192,6 +193,13 @@ QVariant PlayList::data(const QModelIndex &parent, int role) const
                ss << fixed << clips[row].fade_time_seconds;
                return QString::fromStdString(ss.str());
        }
+       case Column::SPEED: {
+               stringstream ss;
+               ss.imbue(locale("C"));
+               ss.precision(3);
+               ss << fixed << clips[row].speed;
+               return QString::fromStdString(ss.str());
+       }
        default:
                return "";
        }
@@ -212,7 +220,7 @@ QVariant ClipList::headerData(int section, Qt::Orientation orientation, int role
        case Column::DURATION:
                return "Duration";
        default:
-               if (section >= int(Column::CAMERA_1) && section < int(Column::CAMERA_1) + num_cameras) {
+               if (is_camera_column(section)) {
                        return QString::fromStdString("Camera " + to_string(section - int(Column::CAMERA_1) + 1));
                } else {
                        return "";
@@ -242,6 +250,8 @@ QVariant PlayList::headerData(int section, Qt::Orientation orientation, int role
                return "Description";
        case Column::FADE_TIME:
                return "Fade time";
+       case Column::SPEED:
+               return "Speed";
        default:
                return "";
        }
@@ -274,7 +284,7 @@ Qt::ItemFlags PlayList::flags(const QModelIndex &index) const
        case Column::DESCRIPTION:
        case Column::CAMERA:
        case Column::FADE_TIME:
-               return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
+       case Column::SPEED:
                return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
        default:
                return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
@@ -319,7 +329,7 @@ bool PlayList::setData(const QModelIndex &index, const QVariant &value, int role
        case Column::CAMERA: {
                bool ok;
                int camera_idx = value.toInt(&ok);
-               if (!ok || camera_idx < 1 || camera_idx > num_cameras) {
+               if (!ok || camera_idx < 1 || camera_idx > int(num_cameras)) {
                        return false;
                }
                clips[row].stream_idx = camera_idx - 1;
@@ -336,6 +346,16 @@ bool PlayList::setData(const QModelIndex &index, const QVariant &value, int role
                emit_data_changed(row);
                return true;
        }
+       case Column::SPEED: {
+               bool ok;
+               double val = value.toDouble(&ok);
+               if (!ok || !(val >= 0.001)) {
+                       return false;
+               }
+               clips[row].speed = val;
+               emit_data_changed(row);
+               return true;
+       }
        default:
                return false;
        }
@@ -413,25 +433,6 @@ void ClipList::change_num_cameras(size_t num_cameras)
        emit any_content_changed();
 }
 
-void PlayList::set_currently_playing(int index, double progress)
-{
-       int old_index = currently_playing_index;
-       int column = int(Column::PLAYING);
-       if (index != old_index) {
-               currently_playing_index = index;
-               play_progress = progress;
-               if (old_index != -1) {
-                       emit dataChanged(this->index(old_index, column), this->index(old_index, column));
-               }
-               if (index != -1) {
-                       emit dataChanged(this->index(index, column), this->index(index, column));
-               }
-       } else if (index != -1 && fabs(progress - play_progress) > 1e-3) {
-               play_progress = progress;
-               emit dataChanged(this->index(index, column), this->index(index, column));
-       }
-}
-
 void PlayList::set_progress(const map<size_t, double> &progress)
 {
        const int column = int(Column::PLAYING);
@@ -462,6 +463,11 @@ Clip deserialize_clip(const ClipProto &clip_proto)
        }
        clip.stream_idx = clip_proto.stream_idx();
        clip.fade_time_seconds = clip_proto.fade_time_seconds();
+       if (clip_proto.speed() < 0.001) {
+               clip.speed = 0.5;  // Default.
+       } else {
+               clip.speed = clip_proto.speed();
+       }
        return clip;
 }
 
@@ -474,6 +480,7 @@ void serialize_clip(const Clip &clip, ClipProto *clip_proto)
        }
        clip_proto->set_stream_idx(clip.stream_idx);
        clip_proto->set_fade_time_seconds(clip.fade_time_seconds);
+       clip_proto->set_speed(clip.speed);
 }
 
 }  // namespace