Browse Source

1,自定义速度逻辑修改 2,添加创建 filter 时长log 3, 不需要循环时 选择速度设置的位置

jsonwang 3 years ago
parent
commit
9d7871c37c

+ 54 - 34
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

@@ -312,23 +312,27 @@ class PQStuckPointEditerController: PQBaseViewController {
     lazy var speedSettingView: PQSpeedSettingView = {
         let speedSettingView = PQSpeedSettingView()
         speedSettingView.backgroundColor = .clear
-        speedSettingView.selectSpeedCallBack = { [weak self] maxSpeed, minSpeed, selectIndex, isSettingPlayer,isCancle in
+        speedSettingView.selectSpeedCallBack = { [weak self] maxSpeed, minSpeed, selectIndex, isSettingPlayer in
             BFLog(message: "固定maxSpeed is\(maxSpeed) minSpeed \(minSpeed)")
          
             if maxSpeed == -1.0 && minSpeed == -1.0 {
                 self?.customSpeedSettingView.isHidden = false
                 self?.customSpeedSettingView.viewType = speedSettingView.viewType
             }else{
-                // 更新最后一次选择的位置恢复时使用
-                if speedSettingView.viewType == 1 {
-                    self?.lastSpeedSelectIndex = selectIndex
-                } else if speedSettingView.viewType == 2 {
-                    self?.lastJumpSpeedSelectIndex = selectIndex
-                } else {
-                    self?.lastCyclesSelectIndex = selectIndex
+                if(maxSpeed != 0.0){
+                    // 更新最后一次选择的位置恢复时使用
+                    if speedSettingView.viewType == 1 {
+                        self?.lastSpeedSelectIndex = selectIndex
+                    } else if speedSettingView.viewType == 2 {
+                        self?.lastJumpSpeedSelectIndex = selectIndex
+                    } else {
+                        self?.lastCyclesSelectIndex = selectIndex
+                    }
+                    self?.maxSpeed = maxSpeed
+                    self?.minSpeed = minSpeed
+                }else{
+                    BFLog(message: "设置速度无效")
                 }
-                self?.maxSpeed = maxSpeed
-                self?.minSpeed = minSpeed
             }
             if isSettingPlayer {
                 self?.settingPlayerView()
@@ -358,7 +362,8 @@ class PQStuckPointEditerController: PQBaseViewController {
                 }else{
                     self?.speedSettingView.setSelectItem(index: self?.lastCyclesSelectIndex ?? 0, isSettingPlayer: false)
                 }
-      
+                
+                customSpeedSettingView.isHidden = true
                
             }
             
@@ -1011,6 +1016,8 @@ extension PQStuckPointEditerController {
     /// - Returns: filters 数据 播放器可直接使用
     func createStickers(sections: List<PQEditSectionModel>, inputSize _: CGSize = .zero, model: createStickersModel = .createStickersModelPoint) -> [PQEditVisionTrackMaterialsModel] {
         // 推荐卡点数
+        let beginDecoderTime: TimeInterval = Date().timeIntervalSince1970
+
         dealParameter(model: model)
         // 保存滤镜对象数据
         var stickers: Array = Array<PQEditVisionTrackMaterialsModel>.init()
@@ -1091,7 +1098,11 @@ extension PQStuckPointEditerController {
                                 for clipindex in 0 ... sticker.clipCount - 1 {
                                     // deep copy sticker model 防止只有一个对象
                                     let stickerjson = sticker.toJSONString(prettyPrint: false)
-                                    let deepCopySticker = Mapper<PQEditVisionTrackMaterialsModel>().map(JSONString: stickerjson!)
+                                    let deepCopyStickerDecoderTime: TimeInterval = Date().timeIntervalSince1970
+
+                                    let deepCopySticker =  Mapper<PQEditVisionTrackMaterialsModel>().map(JSONString: stickerjson!)
+                                    
+                                    BFLog(message: "生成stickers 总时长为 aaa\(Date().timeIntervalSince1970 - deepCopyStickerDecoderTime)")
                                     // 设置循环模式和适配模式
                                     deepCopySticker?.generateDefaultValues()
                                     // 当前分段的速度
@@ -1167,7 +1178,8 @@ extension PQStuckPointEditerController {
                 }
             }
         }
-
+        
+        BFLog(message: "生成stickers 总时长为:\(Date().timeIntervalSince1970 - beginDecoderTime)")
         return stickers
     }
 
@@ -1444,25 +1456,35 @@ extension PQStuckPointEditerController {
                 speedSettingView.setSelectItem(index: lastCyclesSelectIndex, isSettingPlayer: false)
             }
         }else{
-            //不循环 选择1x
-            if lastCyclesSelectIndex != -1 {
-                if(lastCyclesSelectIndex != 0){
-                    for i in 0 ... lastCyclesSelectIndex - 1{
-                        var pointIndex = stuckPointsTemp.firstIndex(where: { (point) -> Bool in
-                            (point == (finallyStuckPoints.last ?? 0).truncatingRemainder(dividingBy: (stuckPointsTemp.last ?? 0)))
-                        })
-                        pointIndex = (pointIndex ?? 0) + 1
-                        for i in 0 ... selectedImageDataCount {
-                            let a = stuckPointsTemp[(i + Int(pointIndex ?? 0)) % stuckPointsTemp.count]
-                            let b = Float((i + Int(pointIndex ?? 0)) / stuckPointsTemp.count) * (stuckPointsTemp.first ?? 0)
-                            finallyStuckPoints.append(a + b)
-                        }
-                    }
-                }
-                speedSettingView.setSelectItem(index: lastCyclesSelectIndex, isSettingPlayer: false)
+            
+            //设置速度选择的位置
+            if speedSettingView.viewType == 1{
+                speedSettingView.setSelectItem(index: lastSpeedSelectIndex , isSettingPlayer: false)
+            }else if speedSettingView.viewType == 2{
+                speedSettingView.setSelectItem(index: lastJumpSpeedSelectIndex, isSettingPlayer: false)
             }else{
-                speedSettingView.setSelectItem(index: 0, isSettingPlayer: false)
+                 speedSettingView.setSelectItem(index: lastCyclesSelectIndex , isSettingPlayer: false)
             }
+            
+//            //不循环 选择1x
+//            if lastCyclesSelectIndex != -1 {
+//                if(lastCyclesSelectIndex != 0){
+//                    for i in 0 ... lastCyclesSelectIndex - 1{
+//                        var pointIndex = stuckPointsTemp.firstIndex(where: { (point) -> Bool in
+//                            (point == (finallyStuckPoints.last ?? 0).truncatingRemainder(dividingBy: (stuckPointsTemp.last ?? 0)))
+//                        })
+//                        pointIndex = (pointIndex ?? 0) + 1
+//                        for i in 0 ... selectedImageDataCount {
+//                            let a = stuckPointsTemp[(i + Int(pointIndex ?? 0)) % stuckPointsTemp.count]
+//                            let b = Float((i + Int(pointIndex ?? 0)) / stuckPointsTemp.count) * (stuckPointsTemp.first ?? 0)
+//                            finallyStuckPoints.append(a + b)
+//                        }
+//                    }
+//                }
+//                speedSettingView.setSelectItem(index: lastCyclesSelectIndex, isSettingPlayer: false)
+//            }else{
+//                speedSettingView.setSelectItem(index: 0, isSettingPlayer: false)
+//            }
           
         }
 
@@ -1676,11 +1698,9 @@ extension PQStuckPointEditerController {
             lastJumpSpeedSelectIndex = 2
         } else if selectedTotalDuration >= 160 && selectedTotalDuration < 200 {
             lastJumpSpeedSelectIndex = 3
-        } else if selectedTotalDuration >= 200 && selectedTotalDuration < 240 {
+        } else if (selectedTotalDuration >= 200 && selectedTotalDuration < 240 ) || selectedTotalDuration >= 240  {
             lastJumpSpeedSelectIndex = 4
-        } else if selectedTotalDuration >= 240 {
-            lastJumpSpeedSelectIndex = 5
-        }
+        } 
 
         /* 默认进入快慢速模式
          - 当素材总时长∈[120,144]s 时,快慢速处理方式:快速为 6x,慢速为 1.2x,效果是快&快

+ 29 - 12
BFFramework/Classes/Stuckpoint/View/PQSpeedSettingView.swift

@@ -76,9 +76,8 @@ class PQSpeedSettingView: UIView {
                      "3x",
                      "4x",
                      "5x",
-                     "6x",
                      "自定义"]
-                let tempMaxSpeed = [1, 2, 3, 4, 5,6, 0]
+                let tempMaxSpeed = [1, 2, 3, 4, 5, 0]
                 for (index, str) in tempTitle.enumerated() {
                     let model = PQSpeedTitleModel()
                     model.title = str
@@ -86,13 +85,20 @@ class PQSpeedSettingView: UIView {
                     datas.append(model)
                 }
             }
+            //如果有老数据先插入 补位
+            if viewType == 3 && lastSelectModel != nil{
+                datas.insert(insertModle!, at: 5)
+            }
 
             titleCollectionView.reloadData()
         }
     }
+    
+    //上一次插入的倍速数据
+    var insertModle:PQSpeedTitleModel?
 
     // 点击回调 maxSpeed,minSpeed 同时为0 说明点击的是自定义速度
-    public var selectSpeedCallBack: ((_ maxSpeed: Float, _ minSpeed: Float,_ selectIndex:Int,_ isSettingPlayer:Bool,_ isCancle:Bool) -> Void)?
+    public var selectSpeedCallBack: ((_ maxSpeed: Float, _ minSpeed: Float,_ selectIndex:Int,_ isSettingPlayer:Bool) -> Void)?
 
     override init(frame: CGRect) {
         super.init(frame: frame)
@@ -119,11 +125,12 @@ class PQSpeedSettingView: UIView {
         // && index < datas.count && (datas[index].title != "自定义" || datas[index].title != "自定义\n快慢速"))
         if viewType == 3{
             if(index > 4 && datas.count < 7){
-                if(index > datas.count){
+                if(index >= datas.count){
                     let model = PQSpeedTitleModel()
                     model.title = "\(index + 1)x"
                     model.maxSpeed = Float(index + 1)
-                    datas.insert(model, at: 5)
+                    insertModle = model
+                    datas.insert(insertModle!, at: 5)
                     lastSelectModel = datas[5]
                 }else{
                     lastSelectModel = datas[index]
@@ -138,14 +145,18 @@ class PQSpeedSettingView: UIView {
         lastSelectModel?.isSelected = true
         titleCollectionView.reloadData()
  
+        
         //发出回调,调用方走统一处理逻辑
         if selectSpeedCallBack != nil {
-            BFLog(message: "选择的速度为 max: \(lastSelectModel?.maxSpeed ?? 0.0) min: \(lastSelectModel?.minSpeed ?? 0.0)")
-            if(lastSelectModel?.title == "自定义" || lastSelectModel?.title == "自定义\n快慢速"){
-                selectSpeedCallBack!(-1,-1,index,false,isCancle)
-            }else{
-                selectSpeedCallBack!(lastSelectModel?.maxSpeed ?? 0.0, lastSelectModel?.minSpeed ?? 0.0,index,isSettingPlayer,isCancle)
-            }
+            BFLog(message: "选择的速度为 max: \(lastSelectModel?.maxSpeed ?? 0.0) min: \(lastSelectModel?.minSpeed ?? 0.0) title  \(lastSelectModel?.title ?? "")")
+      
+                
+            let lastSelectIndex = datas.firstIndex(where: { (model) -> Bool in
+                (model.maxSpeed == lastSelectModel?.maxSpeed)
+            }) ?? 0
+
+            selectSpeedCallBack!(lastSelectModel?.maxSpeed ?? 0.0, lastSelectModel?.minSpeed ?? 0.0,lastSelectIndex,isSettingPlayer)
+       
  
         }
     }
@@ -170,7 +181,13 @@ extension PQSpeedSettingView: UICollectionViewDelegate, UICollectionViewDataSour
             cShowHUB(superView: nil, msg: "素材时长需要大于6秒\n   才可选择其他档位")
             return
         }
-        setSelectItem(index: indexPath.row)
+        
+        if(datas[indexPath.row].title == "自定义" || datas[indexPath.row].title == "自定义\n快慢速"){
+            selectSpeedCallBack!(-1,-1,indexPath.row, false)
+        }else{
+        
+            setSelectItem(index: indexPath.row)
+        }
         //下面只是统计
         if(viewType == 2){
             if(lastSelectModel?.title == "自定义"){