//
//  NvEditTailoringViewController.m
//  SDKDemo
//
//  Created by ms20180425 on 2018/6/13.
 //
//

#import "NvEditTailoringViewController.h"
#import "NvsTimelineEditor.h"
#import "NvsTimelineTimeSpan.h"
#import "CLSlider.h"
#import "NvsVideoFx.h"
#import "NvsVideoTrack.h"
#import "NvsClip.h"
#import "NvEditBottomCollectionViewCell.h"
#import "NvClipLiveWindow.h"
#import "NvTipsView.h"
#import "NvsAudioClip.h"
#import <Photos/Photos.h>
#import <AVFoundation/AVFoundation.h>
#import "NvCorrectionCViewCell.h"

@interface NvEditTailoringViewController ()<NvsTimelineEditorDelegate, UICollectionViewDelegate, UICollectionViewDataSource>

//所有模块统一控件
@property (nonatomic, strong) UILabel *textLabel;                   //标题控件
@property (nonatomic, strong) NvClipLiveWindow *clipLivewindow;     //播放控件

//裁剪、分割模块
@property (nonatomic, strong) NvsTimelineEditor *timeLineEdit;
@property (nonatomic, weak)   NvsTimelineTimeSpan *timeSpan;
@property (nonatomic, assign) int64_t splitTime;                    //分割的时间线
@property (nonatomic, assign) int64_t trimIn;                       //视频裁剪的trimIn
@property (nonatomic, assign) int64_t trimOut;                      //视频裁剪的trimOut
@property (nonatomic, assign) BOOL isModifyLeft;                    //是否修改过trimin
@property (nonatomic, assign) BOOL isModifyRight;                   //是否修改过trimout

//速度模块
@property (nonatomic, strong) UIView *speedControllView;
@property (nonatomic, strong) CLSlider *mSlider;           //速度滑杆

//校色模块
@property (nonatomic, strong) UISlider *brightnessSlider;  //亮度
@property (nonatomic, strong) UISlider *contrastSlider;    //对比度
@property (nonatomic, strong) UISlider *saturationSlider;  //饱和度
@property (nonatomic, strong) UISlider *VigetteSlider;     //暗角
@property (nonatomic, strong) UISlider *SharpenSlider;     //锐度
@property (nonatomic, strong) NSMutableArray *moduleArray; //模块滑动数组
@property (nonatomic, strong) UICollectionView *moduleCollectionView; //模块滑视图
@property (nonatomic, strong) NvCorrectionModel *currentCorrectionModel; //当前滑动对象

//音量模块
@property (nonatomic, strong) UISlider *volumeSlider;      //音量滑杆
@property (nonatomic, strong) UILabel *volumeMaxlabel;     //音量显示

//调整模块
@property (nonatomic, strong) NSArray *adjustArray;                     //按钮数组
@property (nonatomic, strong) UICollectionView *adjustCollectionView;   //按钮视图
@property (nonatomic, strong) UISlider *adjustSlider;                   //角度滑杆
@property (nonatomic, assign) CGFloat currentRotation;                  //旋转按钮--当前的角度
@property (nonatomic, assign) CGPoint anchor;                           //锚点
@property (nonatomic, assign) CGFloat translation;                      //平移点
@property (nonatomic, assign) BOOL xory;                                //判断上下平移还是左右平移

//-----------------sdk相关----------------//
@property (nonatomic, strong) NvsStreamingContext *streamingContext;

@property (nonatomic, strong) NvTimelineData *timelineData;             //数据结构
@property (nonatomic, strong) NvEditDataModel *originClipModel;         //裁剪需要用到

@property (nonatomic, strong) NvsVideoClip *videoClip;                  //视频操作的片段对象
@property (nonatomic, strong) NvsVideoFx *colorVideoFx;                 //片段颜色操作特效
@property (nonatomic, strong) NvsVideoFx *SharpenVideoFx;               //片段锐度特效
@property (nonatomic, strong) NvsVideoFx *VignetteVideoFx;              //片段暗角特效
@property (nonatomic, strong) NvsVideoFx *transVideoFx;                 //片段旋转操作特效
@property (nonatomic, strong) NvsVideoFx *scaleVideoFx;                 //缩放平移操作特效
@property (nonatomic, strong) NvsAudioClip *audioClip;                  //音频操作的片段对象

@property (nonatomic, strong) NvsTimeline *clipTimeline; //这个时间线上只有一个片段
@property (nonatomic, strong) NvsTimeline *timeline;     //这个时间线上包含所有片段

@property (nonatomic, assign) BOOL isSegmentation;                  //是否分割
@end

@implementation NvEditTailoringViewController

- (void)dealloc{
    NSLog(@"%s",__func__);
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.moduleArray = [NSMutableArray array];
    self.streamingContext = [NvsStreamingContext sharedInstance];
    self.clipTimeline = [NvTimelineUtils createTimeline:self.editMode];
    self.timelineData = [NvTimelineData sharedInstance];
    self.timeline = [NvTimelineUtils createTimeline:self.editMode];
    [NvTimelineUtils recreateTimeline:self.timeline];
    
    self.originClipModel = [NvEditDataModel new];
    self.originClipModel.trimIn = _model.trimIn;
    self.originClipModel.trimOut = _model.trimOut;
    self.originClipModel.duration = _model.trimOut - _model.trimIn;
    self.originClipModel.speed = self.model.speed;
    
    if ([self.title isEqualToString:@"裁剪"]) {
        self.model.trimIn = 0;
        self.model.trimOut = _model.duration;
    }
    
    [NvTimelineUtils resetEditData:self.clipTimeline editDataArray:[NSArray arrayWithObject:_model]];
    [NvTimelineUtils resetVideoFx:self.clipTimeline videoFxDataArray:[self getClipTimelineFilter:_model]];
    self.videoClip = [[self.clipTimeline getVideoTrackByIndex:0] getClipWithIndex:0];
    self.audioClip = [[self.clipTimeline getAudioTrackByIndex:0] getClipWithIndex:0];
//    self.videoClip = [NvTimelineUtils getTimelineVideoClip:self.timeline clipInfo:_model];
    self.colorVideoFx = [self getVideoFx:self.videoClip name:@"Color Property"];
    self.transVideoFx = [self getVideoFx:self.videoClip name:@"Transform 2D"];
    self.scaleVideoFx = [self getVideoFx:self.videoClip name:@"Transform 2D"];
    self.SharpenVideoFx = [self getVideoFx:self.videoClip name:@"Sharpen"];
    self.VignetteVideoFx = [self getVideoFx:self.videoClip name:@"Vignette"];
    self.clipLivewindow = [[NvClipLiveWindow alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.width)];
    [self.view addSubview:self.clipLivewindow];
    [self.clipLivewindow connectTimeline:self.clipTimeline];
    self.clipLivewindow.editMode = self.editMode;
    self.clipLivewindow.model = self.originClipModel;
    [self.clipLivewindow setPlayRangeIn:0 rangeOut:self.originClipModel.trimOut/_originClipModel.speed];
    [self.clipLivewindow seekTimeline:0];

    [self addSubViews];
    
    if ([self.title isEqualToString:@"分割"]) {
        if (self.model.trimOut - self.model.trimIn <= 1000000) {
            NvTipsView *tip = [[NvTipsView alloc]initWithFrame:self.view.frame withPrompt:@"提示" describeTitle:@"不可分割小于1秒的素材" describeContent:nil buttonText:@"知道了" withCenter:NO];
            [tip.clickBtn addTarget:self action:@selector(tipClick:) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:tip];
            [self.clipLivewindow seekTimeline:0];
        }
    }
}

- (NSMutableArray *)getClipTimelineFilter:(NvEditDataModel *)clipInfo {
    NSMutableArray *filters = [[NvTimelineData sharedInstance] videoFxDataArray];
    NSMutableArray *clipFilters = NSMutableArray.new;
    for (NvTimeFilterInfoModel *info in filters) {
        NvTimeFilterInfoModel *clipFilter = [info copy];
        clipFilter.inPoint = 0;
        clipFilter.outPoint = _clipTimeline.duration;
        [clipFilters addObject:clipFilter];
    }
    return clipFilters;
}

- (NvsVideoFx *)getVideoFx:(NvsVideoClip *)clip name:(NSString *)name {
    for (int i = 0; i < clip.fxCount; i++) {
        NvsVideoFx *videoFx = [clip getFxWithIndex:i];
        if ([videoFx.bultinVideoFxName isEqualToString:name])
            return videoFx;
    }
    return nil;
}

- (void)tipClick:(UIButton *)sender{
    [sender.superview removeFromSuperview];
    [self.navigationController popViewControllerAnimated:YES];
}

- (UIView *)leftNavigationBarItemView {
    return [UIView new];
}

- (void)addSubViews{
    if ([self.title isEqualToString:@"分割"]) {
        _isSegmentation = YES;
        self.textLabel = [UILabel new];
        self.textLabel.textColor = UIColor.whiteColor;
        self.textLabel.font = [NvUtils fontWithSize:10 * SCREANSCALE];
        self.textLabel.text = [NSString stringWithFormat:@"%@/%@",[NvUtils convertTimecodePrecision:0],[NvUtils convertTimecodePrecision:self.originClipModel.duration/self.originClipModel.speed]];
        [self.view addSubview:_textLabel];
        [self.textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.clipLivewindow.mas_bottom).offset(12 * SCREANSCALE);
            make.centerX.equalTo(self.clipLivewindow.mas_centerX);
        }];
//        self.model.duration = self.originClipModel.duration/_model.speed;
        self.timeLineEdit = [[NvsTimelineEditor alloc] initWithFrame:CGRectMake(13 * SCREANSCALE,426 * SCREANSCALE, 350 * SCREANSCALE,90 * SCREANSCALE)];
        self.timeLineEdit.caneditTimeSpan = YES;
        self.timeLineEdit.canOverlapTimeSpan = YES;
        self.timeLineEdit.type = 1;
        self.timeLineEdit.timelinePosition = (self.model.trimOut - self.model.trimIn)/_model.speed;
        [self.view addSubview:self.timeLineEdit];
        NvsTimelineEditorInfo *info = [[NvsTimelineEditorInfo alloc] init];
        
        info.mediaFilePath = self.model.videoPath;
        info.inPoint = 0;
        info.outPoint = (self.model.trimOut - self.model.trimIn)/_model.speed;
        info.trimIn = self.model.trimIn;
        info.trimOut = self.model.trimOut;
        info.stillImageHint = false;
        [self.timeLineEdit initTimelineEditor:@[info] timelineDuration:(self.model.trimOut - self.model.trimIn)/_model.speed];
        self.timeLineEdit.delegate = self;
        
        self.splitTime = self.model.trimOut / 2.0;
//        NSLog(@"%lld",self.model.trimIn);
//        NSLog(@"%lld",self.model.trimOut);
//        NSLog(@"%lld",self.model.duration);
//        NSLog(@"==%lld",self.originClipModel.trimIn);
//        NSLog(@"==%lld",self.originClipModel.trimOut);
//        NSLog(@"==%lld",self.originClipModel.duration);
        UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [cancelBtn setImage:[NvUtils imageWithName:@"NvSegmentationCancel"] forState:UIControlStateNormal];
        [cancelBtn addTarget:self action:@selector(cancelClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:cancelBtn];
        [cancelBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            if (KIsiPhoneX) {
                make.bottom.equalTo(self.view).offset(-39 * SCREANSCALE);
            }else{
                make.bottom.equalTo(self.view).offset(-15 * SCREANSCALE);
            }
            
            make.left.equalTo(self.view).offset(13 * SCREANSCALE);
        }];
        
        UIButton *finshBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [finshBtn setImage:[NvUtils imageWithName:@"Nvcheck - material"] forState:UIControlStateNormal];
        [finshBtn addTarget:self action:@selector(finshClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:finshBtn];
        [finshBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            if (KIsiPhoneX) {
                make.bottom.equalTo(self.view).offset(-39 * SCREANSCALE);
            }else{
                make.bottom.equalTo(self.view).offset(-15 * SCREANSCALE);
            }
            
            make.right.equalTo(self.view).offset(-13 * SCREANSCALE);
        }];
    }else{
        if ([self.title isEqualToString:@"裁剪"]) {
            self.textLabel = [UILabel new];
            self.textLabel.textColor = UIColor.whiteColor;
            self.textLabel.font = [NvUtils fontWithSize:10 * SCREANSCALE];
            self.textLabel.text = [NSString stringWithFormat:@"裁剪后总时长为%@",[NvUtils convertTimecodePrecision:self.originClipModel.duration/_originClipModel.speed]];
            [self.view addSubview:_textLabel];
            [self.textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.clipLivewindow.mas_bottom).offset(12 * SCREANSCALE);
                make.centerX.equalTo(self.clipLivewindow.mas_centerX);
            }];
            
            self.timeLineEdit = [[NvsTimelineEditor alloc] initWithFrame:CGRectMake(13 * SCREANSCALE,426 * SCREANSCALE, 350 * SCREANSCALE,90 * SCREANSCALE)];
            self.timeLineEdit.caneditTimeSpan = YES;
            self.timeLineEdit.canOverlapTimeSpan = YES;
            self.timeLineEdit.timelinePosition = self.model.duration/_model.speed;
            [self.view addSubview:self.timeLineEdit];
            NvsTimelineEditorInfo *info = [[NvsTimelineEditorInfo alloc] init];
            
            info.mediaFilePath = self.model.videoPath;
            info.inPoint = 0;
            info.outPoint = self.model.duration/_model.speed;
            info.trimIn = self.model.trimIn;
            info.trimOut = self.model.trimOut;
            info.stillImageHint = false;
            [self.timeLineEdit initTimelineEditor:@[info] timelineDuration:self.model.duration/_model.speed];
            self.timeLineEdit.delegate = self;
            self.timeLineEdit.type = 0;
            //添加两边滑块
            self.timeSpan = [self.timeLineEdit addTimeSpan:0 outPoint:self.model.duration/_model.speed];
            self.timeSpan.inPoint = self.originClipModel.trimIn/_model.speed;
            self.timeSpan.outPoint = self.originClipModel.trimOut/_model.speed;
            [self.timeLineEdit updateTrimIn:self.originClipModel.trimIn/_model.speed trimOut:self.originClipModel.trimOut/_model.speed];
            self.clipLivewindow.model = _model;
            [self.clipLivewindow seekTimeline:self.originClipModel.trimIn/_model.speed];
            [self.clipLivewindow setPlayRangeIn:self.originClipModel.trimIn/_model.speed rangeOut:self.originClipModel.trimOut/_model.speed];
//            NSLog(@"%lld",self.originClipModel.trimIn);
//            NSLog(@"%lld",self.originClipModel.trimOut);
            [self.timeSpan setSelected:YES];
            self.timeSpan.editable = YES;
        }else if ([self.title isEqualToString:@"速度"]){
            NSInteger index = 0;
            if (self.model.speed == 1.0/8) {
                index = 0;
            }else if (self.model.speed == 1.0/4){
                index = 1;
            }else if (self.model.speed == 1.0/2){
                index = 2;
            }else if (self.model.speed == 1){
                index = 3;
            }else if (self.model.speed == 1.5){
                index = 4;
            }else if (self.model.speed == 2){
                index = 5;
            }

            self.textLabel = [UILabel new];
            self.textLabel.textColor = UIColor.whiteColor;
            self.textLabel.font = [NvUtils fontWithSize:10 * SCREANSCALE];
            self.textLabel.text = [NSString stringWithFormat:@"按住滑块调整速度"];
            [self.view addSubview:_textLabel];
            [self.textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.clipLivewindow.mas_bottom).offset(40 * SCREANSCALE);
                make.centerX.equalTo(self.view.mas_centerX);
            }];
            
            self.speedControllView = [[UIView alloc]init];
            [self.view addSubview:self.speedControllView];
            [self.speedControllView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.textLabel.mas_bottom).offset(20);
                make.centerX.equalTo(self.view.mas_centerX);
                make.width.offset(250 * SCREANSCALE);
                make.height.offset(60 * SCREANSCALE);
            }];
            
            self.mSlider = [CLSlider new];
            self.mSlider.sliderStyle = CLSliderStyle_Point;
            self.mSlider.thumbDiameter = 13;
            self.mSlider.scaleLineColor = [UIColor whiteColor];
            self.mSlider.scaleLineWidth = 3;
            self.mSlider.scaleLineHeight = 4;
            self.mSlider.scaleLineNumber = 5;
            [self.mSlider setSelectedIndex:index];
            [self.mSlider addTarget:self action:@selector(sliderChangeAction:) forControlEvents:UIControlEventValueChanged];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
            [self.mSlider addGestureRecognizer:tap];
            self.mSlider.frame = CGRectMake(0, 0 * SCREANSCALE, 250 * SCREANSCALE, 30 * SCREANSCALE);
            [self.speedControllView addSubview:self.mSlider];
            
            for (int i = 0; i<6; i++) {
                UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake((i*(247* SCREANSCALE-10* SCREANSCALE)/5.0 * SCREANSCALE) - 15* SCREANSCALE, 40 * SCREANSCALE, 44 * SCREANSCALE, 20 * SCREANSCALE)];
                if (SCREANWIDTH == 320) {
                    lable.frame = CGRectMake((i*(287* SCREANSCALE-10* SCREANSCALE)/5.0 * SCREANSCALE) - 15* SCREANSCALE, 40 * SCREANSCALE, 44 * SCREANSCALE, 20 * SCREANSCALE);
                }else if(SCREANWIDTH == 414){
                    lable.frame = CGRectMake((i*(225* SCREANSCALE-10* SCREANSCALE)/5.0 * SCREANSCALE) - 15* SCREANSCALE, 40 * SCREANSCALE, 44 * SCREANSCALE, 20 * SCREANSCALE);
                }
                lable.textAlignment = NSTextAlignmentCenter;
                lable.textColor = UIColor.whiteColor;
                lable.font = [NvUtils fontWithSize:10 * SCREANSCALE];
                [self.speedControllView addSubview:lable];
                switch (i) {
                    case 0:
                        lable.text = @"1/8X";
                        break;
                    case 1:
                        lable.text = @"1/4X";
                        break;
                    case 2:
                        lable.text = @"1/2X";
                        break;
                    case 3:
                        lable.text = @"1X";
                        break;
                    case 4:
                        lable.text = @"1.5X";
                        break;
                    case 5:
                        lable.text = @"2X";
                        break;
                    default:
                        break;
                }
            }
        }else if ([self.title isEqualToString:@"校色"]){
            NSArray *valueArray = @[[NSString stringWithFormat:@"%f",self.model.brightness],
                                    [NSString stringWithFormat:@"%f",self.model.contrast],
                                    [NSString stringWithFormat:@"%f",self.model.saturation],
                                    [NSString stringWithFormat:@"%f",self.model.Vignette],
                                    [NSString stringWithFormat:@"%f",self.model.Sharpen],
            ];
            NSArray *correctionTitle = @[@"亮度", @"对比度", @"饱和度", @"暗角", @"锐度"];
            NSArray *correctionTitle1 = @[@"Brightness", @"Contrast", @"Saturation", @"Degree", @"Amount"];
            for (int i = 0; i < correctionTitle.count; i++) {
                NvCorrectionModel *correctionModel = [NvCorrectionModel new];
                UISlider *correction_slider = [UISlider new];
                if (i == 0) {
                    self.currentCorrectionModel = correctionModel;
                    correctionModel.select = YES;
                }else{
                    correctionModel.select = NO;
                }
                if ([correctionTitle[i] isEqualToString:@"暗角"]) {
                    [correction_slider setMinimumValue:0];
                    [correction_slider setMaximumValue:1];
                }else if ([correctionTitle[i] isEqualToString:@"锐度"]){
                    [correction_slider setMinimumValue:0];
                    [correction_slider setMaximumValue:5];
                }else{
                    [correction_slider setMinimumValue:0];
                    [correction_slider setMaximumValue:2];
                }
                
                correction_slider.minimumTrackTintColor = [UIColor nv_colorWithHexRGB:@"#979797"];
                correction_slider.maximumTrackTintColor = [UIColor nv_colorWithHexRGB:@"#979797"];
                [correction_slider setThumbImage:[NvUtils imageWithName:@"NvSliderIcon"] forState:UIControlStateNormal];
                [correction_slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
                [self.view addSubview:correction_slider];
                
                
                correction_slider.value = [valueArray[i] floatValue];
                correctionModel.text = correctionTitle[i];
                correctionModel.slider = correction_slider;
                correctionModel.typeString = correctionTitle1[i];
                
                [self.moduleArray addObject:correctionModel];
                
                [correction_slider mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.equalTo(self.clipLivewindow.mas_bottom).offset(72 * SCREANSCALE);
                    make.centerX.equalTo(self.view);
                    make.width.offset(350 * SCREANSCALE);
                    make.height.offset(10);
                }];
            }
            
            UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
            layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
            layout.itemSize = CGSizeMake(SCREANWIDTH/correctionTitle.count * SCREANSCALE, 60 * SCREANSCALE);
            layout.minimumLineSpacing = 10 * SCREANSCALE;
            layout.minimumInteritemSpacing = 0;
            layout.sectionInset = UIEdgeInsetsMake(0, 10*SCREANSCALE, 0, 0);
            _moduleCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0,0,0) collectionViewLayout:layout];
            _moduleCollectionView.delegate = self;
            _moduleCollectionView.dataSource = self;
            _moduleCollectionView.backgroundColor = [UIColor clearColor];
            _moduleCollectionView.showsHorizontalScrollIndicator = NO;
            [self.view addSubview:_moduleCollectionView];
            [_moduleCollectionView registerClass:[NvCorrectionCViewCell class] forCellWithReuseIdentifier:@"NvCorrectionCViewCell"];
            [_moduleCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.clipLivewindow.mas_bottom).offset(100 * SCREANSCALE);
                make.centerX.equalTo(self.view);
                make.width.offset(SCREANWIDTH);
                make.height.offset(60 * SCREANSCALE);
            }];
            
        }else if ([self.title isEqualToString:@"音量"]){

            
            UILabel *volumeLabel = [UILabel new];
            volumeLabel.text = @"音量";
            volumeLabel.textColor = UIColor.whiteColor;
            volumeLabel.font = [NvUtils fontWithSize:12 * SCREANSCALE];
            [self.view addSubview:volumeLabel];
            
            UILabel *minlabel = [UILabel new];
            minlabel.text = @"0";
            minlabel.textColor = UIColor.whiteColor;
            minlabel.font = [NvUtils fontWithSize:12 * SCREANSCALE];
            [self.view addSubview:minlabel];
            
            self.volumeSlider = [UISlider new];
            [self.volumeSlider setMinimumValue:0];
            [self.volumeSlider setMaximumValue:100];
            self.volumeSlider.minimumTrackTintColor = [UIColor nv_colorWithHexRGB:@"#979797"];
            self.volumeSlider.maximumTrackTintColor = [UIColor nv_colorWithHexRGB:@"#979797"];
            [self.volumeSlider setThumbImage:[NvUtils imageWithName:@"Nvslider"] forState:UIControlStateNormal];
            [self.volumeSlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
            [self.view addSubview:self.volumeSlider];
            
            self.volumeMaxlabel = [UILabel new];
            self.volumeMaxlabel.text = [NSString stringWithFormat:@"%d",(int)(self.model.volume * 50)];
            self.volumeMaxlabel.textColor = UIColor.whiteColor;
            self.volumeMaxlabel.font = [NvUtils fontWithSize:12 * SCREANSCALE];
            [self.view addSubview:self.volumeMaxlabel];
            
            [volumeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.clipLivewindow.mas_bottom).offset(72 * SCREANSCALE);
                make.left.equalTo(self.view).offset(13 * SCREANSCALE);
            }];
            
            [minlabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(volumeLabel.mas_right).offset(18 * SCREANSCALE);
                make.centerY.equalTo(volumeLabel.mas_centerY);
            }];
            
            [self.volumeSlider mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(minlabel.mas_right).offset(11 * SCREANSCALE);
                make.centerY.equalTo(volumeLabel.mas_centerY);
                make.width.offset(254 * SCREANSCALE);
                make.height.offset(10 * SCREANSCALE);
            }];
            
            [self.volumeMaxlabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.volumeSlider.mas_right).offset(11 * SCREANSCALE);
                make.centerY.equalTo(volumeLabel.mas_centerY);
            }];
            
            self.volumeSlider.value = self.model.volume * 50;
        }else if ([self.title isEqualToString:@"调整"]){
            self.adjustArray = @[@{@"水平":@"NvAdjustVertical"},@{@"垂直":@"NvAdjustLevel"},@{@"旋转":@"NvAdjustRotating"},@{@"复位":@"NvAdjustReset"}];
            
            if (self.model.asset) {
                if (self.model.asset.pixelWidth > self.model.asset.pixelHeight) {
                    self.xory = YES;
                }else{
                    self.xory = NO;
                }
            }else{
                NvsAVFileInfo *info = [self.streamingContext getAVFileInfo:self.model.videoPath];
                NvsSize videoSize = [info getVideoStreamDimension:0];
                if (videoSize.width > videoSize.height) {
                    self.xory = YES;
                }else{
                    self.xory = NO;
                }
            }

            
            UILabel *angleLabel = [UILabel new];
            angleLabel.text = @"角度";
            angleLabel.textColor = UIColor.whiteColor;
            angleLabel.font = [NvUtils fontWithSize:15 * SCREANSCALE];
//            [self.view addSubview:angleLabel];
            
            UILabel * angleMinLabel = [UILabel new];
            angleMinLabel.text = @"-45";
            angleMinLabel.textColor = UIColor.whiteColor;
            angleMinLabel.font = [NvUtils fontWithSize:12 * SCREANSCALE];
//            [self.view addSubview:angleMinLabel];
            
            self.adjustSlider = [UISlider new];
            [self.adjustSlider setMinimumValue:-45];
            [self.adjustSlider setMaximumValue:45];
            self.adjustSlider.minimumTrackTintColor = [UIColor nv_colorWithHexRGB:@"#979797"];
            self.adjustSlider.maximumTrackTintColor = [UIColor nv_colorWithHexRGB:@"#979797"];
            [self.adjustSlider setThumbImage:[NvUtils imageWithName:@"Nvslider"] forState:UIControlStateNormal];
            [self.adjustSlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
//            [self.view addSubview:self.adjustSlider];
            
            UILabel * angleMaxLabel = [UILabel new];
            angleMaxLabel.text = @"45";
            angleMaxLabel.textColor = UIColor.whiteColor;
            angleMaxLabel.font = [NvUtils fontWithSize:12 * SCREANSCALE];

            UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
            layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
            layout.itemSize = CGSizeMake(58*SCREANSCALE, 70*SCREANSCALE);
            layout.minimumLineSpacing = 10*SCREANSCALE;
            layout.minimumInteritemSpacing = 0;
            layout.sectionInset = UIEdgeInsetsMake(0, (SCREEN_WDITH - 262 * SCREANSCALE) * 0.5, 0, 0);
            self.adjustCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0 * SCREANSCALE, 462, SCREEN_WDITH, 80*SCREANSCALE) collectionViewLayout:layout];
            _adjustCollectionView.backgroundColor = UIColor.clearColor;
            _adjustCollectionView.delegate = self;
            _adjustCollectionView.dataSource = self;
            _adjustCollectionView.showsHorizontalScrollIndicator = NO;
            [self.view addSubview:_adjustCollectionView];
            [_adjustCollectionView registerClass:[NvEditBottomCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
            [_adjustCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
//                make.top.equalTo(self.adjustSlider.mas_bottom).offset(20*SCREANSCALE);
                make.top.equalTo(self.clipLivewindow.mas_bottom).offset(58*SCREANSCALE);
                make.left.right.equalTo(@0);
                make.height.equalTo(@(80*SCREANSCALE));
            }];
            
            UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchGesture:)];
            [self.clipLivewindow.liveWindow addGestureRecognizer:pinch];

            UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGesture:)];
            [self.clipLivewindow.liveWindow addGestureRecognizer:pan];
        }
        UIButton *finshBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [finshBtn setImage:[NvUtils imageWithName:@"Nvcheck - material"] forState:UIControlStateNormal];
        [finshBtn addTarget:self action:@selector(finshClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:finshBtn];
        [finshBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            if (KIsiPhoneX) {
                 make.bottom.equalTo(self.view).offset(-39 * SCREANSCALE);
            }else{
                 make.bottom.equalTo(self.view).offset(-15 * SCREANSCALE);
            }
           
            make.centerX.equalTo(self.view.mas_centerX);
        }];
        
        UIView *line = [UIView new];
        line.backgroundColor = [UIColor nv_colorWithHexARGB:@"#1AFFFFFF"];
        [self.view addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(@0);
            make.height.equalTo(@1);
            make.bottom.equalTo(finshBtn.mas_top).offset(-12*SCREANSCALE);
        }];
    }
    [self.clipLivewindow play];
}

#pragma mark 缩放手势事件
- (void)pinchGesture:(UIPinchGestureRecognizer *)pinch{
    if (pinch.state==UIGestureRecognizerStateBegan) {
        pinch.scale = self.model.scan + 1;
//        if (self.model.scaleX > 0 && self.model.scaleY > 0 ){
//            pinch.scale = self.model.scaleX;
//        }else if (self.model.scaleX < 0 && self.model.scaleY > 0){
//            pinch.scale = self.model.scaleX;
//        }else if (self.model.scaleY < 0 && self.model.scaleX > 0){
//            pinch.scale = self.model.scaleY;
//        }else{
//            pinch.scale = self.model.scaleX;
//        }
//        self.anchor = [pinch locationInView:self.clipLivewindow.liveWindow];
//        self.anchor = [self conversionPoint:self.anchor];
//        [self.scaleVideoFx setFloatVal:@"Anchor X" val:self.anchor.x * 1000];
//        [self.scaleVideoFx setFloatVal:@"Anchor Y" val:self.anchor.y * 1000];
    }else if (pinch.state==UIGestureRecognizerStateChanged){
        [self.clipLivewindow seekTimeline:0];
        if (pinch.scale >= 2) {
            pinch.scale = 2;
        }
        if (pinch.scale <= 1){
            pinch.scale = 1;
        }
        if (pinch.scale >= 1 && pinch.scale <= 2) {
            self.model.scan = pinch.scale - 1.0;
            [self.videoClip setPan:self.model.pan andScan:self.model.scan];
        }
//        if (pinch.scale <= 1 && pinch.scale >=0) {
//            pinch.scale = 1;
//        }
//        if (pinch.scale <=0 && pinch.scale >= -1) {
//            pinch.scale = -1;
//        }
//        if (self.model.scaleX > 0 && self.model.scaleY > 0 ){
////        self.clipLivewindow.liveWindow.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);
//            [self.scaleVideoFx setFloatVal:@"Scale X" val:pinch.scale];
//            [self.scaleVideoFx setFloatVal:@"Scale Y" val:pinch.scale];
//            self.model.scaleX = pinch.scale;
//            self.model.scaleY = pinch.scale;
//        }else if (self.model.scaleX < 0 && self.model.scaleY > 0){
////            self.clipLivewindow.liveWindow.transform = CGAffineTransformMakeScale(pinch.scale, -pinch.scale);
//            [self.scaleVideoFx setFloatVal:@"Scale X" val:pinch.scale];
//            [self.scaleVideoFx setFloatVal:@"Scale Y" val: -pinch.scale];
//            self.model.scaleX = pinch.scale;
//            self.model.scaleY = -pinch.scale;
//        }else if (self.model.scaleY < 0 && self.model.scaleX > 0){
////            self.clipLivewindow.liveWindow.transform = CGAffineTransformMakeScale(-pinch.scale, pinch.scale);
//            [self.scaleVideoFx setFloatVal:@"Scale X" val:-pinch.scale];
//            [self.scaleVideoFx setFloatVal:@"Scale Y" val:pinch.scale];
//            self.model.scaleX = -pinch.scale;
//            self.model.scaleY = pinch.scale;
//        }else{
////            self.clipLivewindow.liveWindow.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);
//            [self.scaleVideoFx setFloatVal:@"Scale X" val:pinch.scale];
//            [self.scaleVideoFx setFloatVal:@"Scale Y" val:pinch.scale];
//            self.model.scaleX = pinch.scale;
//            self.model.scaleY = pinch.scale;
//        }
    }else if (pinch.state == UIGestureRecognizerStateEnded){
        [self.clipLivewindow play];
    }
}

#pragma mark 是否允许多个手势并发
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return NO;
}

#pragma mark 平移手势事件
- (void)panGesture:(UIPanGestureRecognizer *)pan{
    
//    CGPoint point = [pan translationInView:_clipLivewindow.liveWindow];
//    CGAffineTransform translation = CGAffineTransformMakeTranslation(point.x, point.y);
//    //在缩放基础上叠加平移
//    CGAffineTransform scaleTranslation = CGAffineTransformScale(translation, self.model.scaleX, self.model.scaleX);
//    self.clipLivewindow.liveWindow.transform = scaleTranslation;
//    if (self.model.scaleX == 1 || self.model.scaleX == -1 || self.model.scaleY == 1 || self.model.scaleY == -1) {
//        return;
//    }
    if (pan.state == UIGestureRecognizerStateBegan) {
//        [self.scaleVideoFx setFloatVal:@"Anchor X" val:self.translation.x];
//        [self.scaleVideoFx setFloatVal:@"Anchor Y" val:self.translation.y];
//        [self.scaleVideoFx setFloatVal:@"Trans X" val:self.translation.x];
//        [self.scaleVideoFx setFloatVal:@"Trans Y" val:self.translation.y];
//        NSLog(@"开始=======%f,%f",self.translation.x,self.translation.y);
    }else if (pan.state == UIGestureRecognizerStateChanged) {
        [self.clipLivewindow seekTimeline:0];
        CGPoint iiiii = [pan translationInView:self.clipLivewindow.liveWindow];
        if (_xory) {
            if (((int)self.model.rotation%90)%2 == 0) {
                //偶数
                self.translation = -iiiii.x;
            }else{
                //奇数
                self.translation = iiiii.y;
            }
        }else{
            if (((int)self.model.rotation%90)%2 == 0) {
                self.translation = iiiii.y;
            }else{
                self.translation = -iiiii.x;
            }
        }
        
        if (self.translation >= 100) {
            self.translation = 100;
        }
        if (self.translation <= -100) {
            self.translation = -100;
        }
        if (self.translation >= -100 && self.translation <= 100) {
            self.translation = self.translation / 100.0;
            [self.videoClip setPan:self.translation + self.model.pan andScan:self.model.scan];
        }
        
//        CGPoint point = [pan locationInView:_clipLivewindow.liveWindow];
//        point = [self conversionPoint:CGPointMake(point.x,point.y)];
//        point = CGPointMake(point.x * 1000, point.y * 1000);
//        NSLog(@"%f,%f",self.model.translation.x,point.y);
//        [self.scaleVideoFx setFloatVal:@"Trans X" val:point.x];
//        [self.scaleVideoFx setFloatVal:@"Trans Y" val:point.y];
//        self.translation = point;
    }else if(pan.state == UIGestureRecognizerStateEnded){
        self.model.pan = self.translation + self.model.pan;
        if (self.model.pan >= 1) {
            self.model.pan =1;
        }
        if (self.model.pan <= -1) {
            self.model.pan = -1;
        }
        [self.clipLivewindow play];
//        self.model.translation = self.translation;
    }
}

#pragma mark 两点间的距离
- (BOOL)distancePreviousPoint:(CGPoint)previous point:(CGPoint)current{
    CGFloat distance = sqrtf(powf(previous.x - current.x, 2) + powf(previous.y - current.y, 2));
    if (distance > 10) {
        return YES;
    }
    return NO;
}

#pragma mark 坐标转换
- (CGPoint)conversionPoint:(CGPoint)point{
    CGPoint currtnetPoint = [_clipLivewindow.liveWindow mapViewToNormalized:point];
    return currtnetPoint;
}

#pragma mark 取消按钮点击事件
- (void)cancelClick:(UIButton *)sender{
    [NvTimelineUtils removeTimeline:self.clipTimeline];
    [NvTimelineUtils removeTimeline:self.timeline];
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark 完成按钮点击事件
- (void)finshClick:(UIButton *)sender{
    if ([self.title isEqualToString:@"裁剪"]) {
        if (_isModifyLeft) {
            self.model.trimIn = self.trimIn*_model.speed;
        }else{
            self.model.trimIn = self.originClipModel.trimIn;
        }
        if (_isModifyRight) {
            self.model.trimOut = self.trimOut*_model.speed;
        }else{
            self.model.trimOut = self.originClipModel.trimOut;
        }
    } else if ([self.title isEqualToString:@"分割"]) {
        if (_isSegmentation) {
            NvEditDataModel *dataModel = [self.model copy];
//            NSLog(@"%f",self.splitTime*_model.speed);
//            NSLog(@"%lld", dataModel.trimIn);
//            NSLog(@"%lld", dataModel.trimOut);
//            NSLog(@"%lld", _model.trimIn);
//            NSLog(@"%lld", _model.trimOut);
            dataModel.trimIn = self.splitTime*_model.speed + self.model.trimIn;
            self.model.trimOut = self.splitTime*_model.speed + self.model.trimIn;
            [self.timelineData.editDataArray insertObject:dataModel atIndex:self.currentIndex + 1];
            self.editBlock(dataModel);
        }
    } else if ([self.title isEqualToString:@"校色"]) {

    } else if ([self.title isEqualToString:@"调整"]) {
        
    } else if ([self.title isEqualToString:@"速度"]) {
        
    } else if ([self.title isEqualToString:@"音量"]) {
        
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark 校色，音量，调整slider统一回调事件
- (void)sliderValueChanged:(UISlider *)slider{
//    if ([slider isEqual:self.brightnessSlider]) {
//        self.model.brightness = slider.value;
//       [_colorVideoFx setFloatVal:@"Brightness" val:self.model.brightness];
//        [_colorVideoFx setFloatVal:@"Brightness" val:self.model.brightness];
//    }else if ([slider isEqual:self.contrastSlider]){
//        self.model.contrast = slider.value;
//        [_colorVideoFx setFloatVal:@"Contrast" val:self.model.contrast];
//        [_colorVideoFx setFloatVal:@"Contrast" val:self.model.contrast];
//    }else if ([slider isEqual:self.saturationSlider]){
//        self.model.saturation = slider.value;
//        [_colorVideoFx setFloatVal:@"Saturation" val:self.model.saturation];
//        [_colorVideoFx setFloatVal:@"Saturation" val:self.model.saturation];
    if ([slider isEqual:self.volumeSlider]) {
        int volume = slider.value;
        self.model.volume = volume/50.0;
        self.volumeMaxlabel.text = [NSString stringWithFormat:@"%d",volume];
//        self.textLabel.text = [NSString stringWithFormat:@"%d",volume];
        [_videoClip setVolumeGain:self.model.volume rightVolumeGain:self.model.volume];
    }else if ([slider isEqual:self.adjustSlider]) {
        if (self.currentRotation > 0) {
            self.model.rotation = slider.value + self.currentRotation;
        }else{
            self.model.rotation = slider.value;
        }
        [_transVideoFx setFloatVal:@"Rotation" val:self.model.rotation];
    }else{
        if ([self.currentCorrectionModel.text isEqualToString:@"亮度"]) {
            self.model.brightness = slider.value;
            [_colorVideoFx setFloatVal:self.currentCorrectionModel.typeString val:slider.value];
        }else if ([self.currentCorrectionModel.text isEqualToString:@"对比度"]){
            self.model.contrast = slider.value;
            [_colorVideoFx setFloatVal:self.currentCorrectionModel.typeString val:slider.value];
        }else if ([self.currentCorrectionModel.text isEqualToString:@"饱和度"]){
            self.model.saturation = slider.value;
            [_colorVideoFx setFloatVal:self.currentCorrectionModel.typeString val:slider.value];
        }else if ([self.currentCorrectionModel.text isEqualToString:@"暗角"]){
            self.model.Vignette = slider.value;
            [_VignetteVideoFx setFloatVal:self.currentCorrectionModel.typeString val:slider.value];
        }else if ([self.currentCorrectionModel.text isEqualToString:@"锐度"]){
            self.model.Sharpen = slider.value;
            [_SharpenVideoFx setFloatVal:self.currentCorrectionModel.typeString val:slider.value];
        }
    }
    if (self.clipLivewindow.isPause) {
        [self.clipLivewindow play];
    }
    //    [self.streamingContext seekTimeline:self.clipTimeline timestamp:[self.streamingContext getTimelineCurrentPosition:self.clipTimeline] videoSizeMode:NvsVideoPreviewSizeModeLiveWindowSize flags:NvsStreamingEngineSeekFlag_ShowCaptionPoster | NvsStreamingEngineSeekFlag_ShowAnimatedStickerPoster];
    //    [NvTimelineUtils resetEditData:self.timeline editDataArray:@[_model]];
}

#pragma mark timelineEditorDelegate
//滑动一直改变
- (void)timelineEditor:(id)timelineEditor draggingHandle:(int64_t)timestamp isInPoint:(bool)isInPoint{
    if (isInPoint) {
        self.isModifyLeft = YES;
        self.trimIn = timestamp;
        [self.clipLivewindow seekTimeline:self.trimIn];
        [self.clipLivewindow setPlayRangeIn:self.trimIn rangeOut:self.trimOut];
    }else{
        self.isModifyRight = YES;
        self.trimOut = timestamp;
        [self.clipLivewindow seekTimeline:self.trimOut];
        [self.clipLivewindow setPlayRangeIn:self.trimIn rangeOut:self.trimOut];
    }
    if (self.trimOut == 0.0) {
        self.trimOut = self.model.duration/_model.speed;
    }
    self.textLabel.text = [NSString stringWithFormat:@"裁剪后总时长为%@",[NvUtils convertTimecodePrecision:self.trimOut - self.trimIn]];
    
//    NSLog(@"%----lld",self.trimOut);
//    NSLog(@"%----lld",self.trimIn);
    
}

//滑动改变停止
- (void)timelineEditor:(id)timelineEditor dragHandleEnded:(int64_t)timestamp isInPoint:(bool)isInPoint{
    
}

//分割功能：时码线控件回调事件
- (void)timelineEditor:(id)timelineEditor handlePan:(int64_t)timestamp{
    self.textLabel.text = [NSString stringWithFormat:@"%@/%@",[NvUtils convertTimecodePrecision:timestamp],[NvUtils convertTimecodePrecision:(self.originClipModel.duration/_model.speed-timestamp)]];
//    NSLog(@"%lld",timestamp);
//    NSLog(@"%lld",self.model.duration);
    if (timestamp <= 0 || timestamp >= self.model.duration) {
        _isSegmentation = NO;
    }else{
        _isSegmentation = YES;
    }
    
    self.splitTime = timestamp;
    [self.clipLivewindow seekTimeline:timestamp];
}

// 定位某一时间戳的图像
- (void)seekTimeline:(int64_t)postion {
    if (![_streamingContext seekTimeline:self.clipTimeline timestamp:postion videoSizeMode:NvsVideoPreviewSizeModeLiveWindowSize flags:NvsStreamingEngineSeekFlag_ShowCaptionPoster | NvsStreamingEngineSeekFlag_ShowAnimatedStickerPoster])
        NSLog(@"定位时间线失败！");
}

#pragma mark 速度模块回调事件
//速度滑杆控件，滑动时回调事件
- (void)sliderChangeAction:(CLSlider*)clSlider {
    NSInteger index = clSlider.currentIdx;
    float speed = 1;
    switch (index) {
        case 0:
            speed = 1.0/8;
            break;
        case 1:
            speed = 1.0/4;
            break;
        case 2:
            speed = 1.0/2;
            break;
        case 3:
            speed = 1;
            break;
        case 4:
            speed = 1.5;
            break;
        case 5:
            speed = 2;
            break;
        default:
            break;
    }
    self.model.speed = speed;
    self.originClipModel.speed = speed;
//    [self.videoClip changeSpeed:self.model.speed keepAudioPitch:NO];
    [NvTimelineUtils resetEditData:self.clipTimeline editDataArray:@[_model]];
    [self.clipLivewindow setPlayRangeIn:0 rangeOut:self.originClipModel.trimOut/_originClipModel.speed];
    [self.clipLivewindow seekTimeline:0];
    [self.clipLivewindow play];
}

//速度滑杆控件，点击按钮回调事件
- (void)tapClick:(UITapGestureRecognizer *)tapGestureRecognizer {
    CGPoint tapPoint = [tapGestureRecognizer locationInView:self.mSlider];
    for (int i = 0; i < 6; i++) {
        CGRect rect = CGRectMake((i*(250-10) * SCREANSCALE/5.0 * SCREANSCALE) - 15, 0, 44, 30);
        if (SCREANWIDTH == 320) {
            rect = CGRectMake((i*(287* SCREANSCALE-10* SCREANSCALE)/5.0 * SCREANSCALE) - 15* SCREANSCALE, 0 * SCREANSCALE, 44 * SCREANSCALE, 30 * SCREANSCALE);
        }else if(SCREANWIDTH == 414){
            rect = CGRectMake((i*(225* SCREANSCALE-10* SCREANSCALE)/5.0 * SCREANSCALE) - 15* SCREANSCALE, 0 * SCREANSCALE, 44 * SCREANSCALE, 30 * SCREANSCALE);
        }
        if (CGRectContainsPoint(rect,tapPoint)) {
            [self.mSlider setSelectedIndex:i];
            [self sliderChangeAction:self.mSlider];
        }
    }
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if ([collectionView isEqual: _moduleCollectionView]) {
        return self.moduleArray.count;
    }
    return self.adjustArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if ([collectionView isEqual: _moduleCollectionView]) {
        NvCorrectionCViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NvCorrectionCViewCell" forIndexPath:indexPath];
        [cell renderCellWithModel:self.moduleArray[indexPath.item]];
        return cell;
    }
    NvEditBottomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.dict = self.adjustArray[indexPath.item];
    return cell;
}

#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if ([collectionView isEqual:_moduleCollectionView]) {
        self.currentCorrectionModel = self.moduleArray[indexPath.item];
        for (NvCorrectionModel *model in _moduleArray) {
            model.select = NO;
        }
        self.currentCorrectionModel.select = YES;
        [collectionView reloadData];
    }else{
        if (indexPath.item == 0) {
            if (self.model.scaleX > 0) {
                self.model.scaleX = -1;
            }else{
                self.model.scaleX = 1;
            }
            //        self.model.scaleX = -self.model.scaleX;
            //水平
            [_transVideoFx setFloatVal:@"Scale X" val:self.model.scaleX];
        }else if (indexPath.item == 1){
            //垂直
            //        self.model.scaleY = -self.model.scaleY;
            if (self.model.scaleY > 0) {
                self.model.scaleY = -1;
            }else{
                self.model.scaleY = 1;
            }
            [_transVideoFx setFloatVal:@"Scale Y" val:self.model.scaleY];
        }else if (indexPath.item == 2){
            //旋转
            //        self.model.rotation += 90;
            if ((int)self.model.rotation >= 3) {
                self.model.rotation = -1;
            }
            self.model.rotation++;
            self.currentRotation += 90;
            [_videoClip setExtraVideoRotation:self.model.rotation];
            //        [_transVideoFx setFloatVal:@"Rotation" val:self.model.rotation];
        }else if (indexPath.item == 3){
            //复位
            self.model.scaleX = 1;
            self.model.scaleY = 1;
            self.model.pan = 0;
            self.model.scan = 0;
            self.model.rotation = 0;
            [_transVideoFx setFloatVal:@"Scale X" val:self.model.scaleX];
            [_transVideoFx setFloatVal:@"Scale Y" val:self.model.scaleY];
            [self.videoClip setPan:self.model.pan andScan:self.model.scan];
            [_videoClip setExtraVideoRotation:self.model.rotation];
            //        [_transVideoFx setFloatVal:@"Rotation" val:self.model.rotation];
        }
        if (self.clipLivewindow.isPause) {
            [self.clipLivewindow play];
        }
        //[NvTimelineUtils resetEditData:self.timeline editDataArray:@[_model]];
        //[self.clipLivewindow seekTimeline:0];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
