Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a loop count setting #218

Merged
merged 30 commits into from
Dec 27, 2020
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1841740
feat: gifski cli can limit animation loops
0bmay Nov 24, 2020
dee11e7
feat: max loops for conversions
0bmay Nov 25, 2020
8eb2c2d
Update EditVideoViewController.swift
sindresorhus Nov 25, 2020
49215fe
fix: revert Development Team updates
0bmay Nov 25, 2020
439473b
Merge remote-tracking branch 'origin/master'
0bmay Nov 25, 2020
2faf66f
fix: timesShown is now loopCount
0bmay Nov 25, 2020
50d4861
fix: loop count for gifsicle
0bmay Nov 25, 2020
b052902
fix: looping Controls UI flow
0bmay Nov 25, 2020
725e769
feat: stepper control for loop count
0bmay Nov 25, 2020
38e0981
fix: variable fixes while updating upstream gifski
0bmay Nov 25, 2020
0411ade
fix: logic flow change for looping in gifski library
0bmay Nov 26, 2020
66e6fe4
fix: loop controls
0bmay Nov 26, 2020
13b5696
fix: Looping Logic
0bmay Nov 26, 2020
50cf2ef
Update EditVideoViewController.swift
sindresorhus Nov 27, 2020
731fc92
fix: ui updates and ease of change modifications
0bmay Nov 27, 2020
4c9e717
Merge branch 'master' into master
sindresorhus Nov 28, 2020
7b5e039
fix: code review updates
0bmay Nov 28, 2020
87612c2
Merge remote-tracking branch 'origin/master'
0bmay Nov 28, 2020
7837ab3
fix: UI Contraints
0bmay Nov 28, 2020
61caefa
feat: animation repeat
0bmay Dec 17, 2020
b311da4
feat: animation looping updates from gifski cli
0bmay Dec 18, 2020
d4a9694
Update EditVideoViewController.swift
sindresorhus Dec 18, 2020
d647ba3
Update EditVideoViewController.swift
sindresorhus Dec 18, 2020
b40f2be
fix: Loop Forever and Loop Count states
0bmay Dec 18, 2020
9bce926
fix: Animation Preview Warning
0bmay Dec 22, 2020
cded813
Update Gifski/EditVideoViewController.swift
0bmay Dec 23, 2020
0b6189c
fix: changed gif loop warning message
0bmay Dec 23, 2020
359097b
fix: shortened looping warning message
0bmay Dec 23, 2020
51f6863
fix: updated code comment and warning text for specific loop counts
0bmay Dec 25, 2020
6e2db7f
Update EditVideoViewController.swift
sindresorhus Dec 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gifski/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ struct Constants {
static let defaultWindowSize = CGSize(width: 360, height: 240)
static let backgroundImage = NSImage(named: "BackgroundImage")!
static let allowedFrameRate = 5.0...50.0
static let loopCountRange = 0...100
}

extension NSColor {
Expand Down
94 changes: 92 additions & 2 deletions Gifski/EditVideoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ final class EditVideoViewController: NSViewController {
@IBOutlet private var dimensionsTypeDropdown: MenuPopUpButton!
@IBOutlet private var cancelButton: NSButton!
@IBOutlet private var playerViewWrapper: NSView!
@IBOutlet private var loopCountTextField: IntTextField!
@IBOutlet private var loopCountStepper: NSStepper!

var inputUrl: URL!
var asset: AVAsset!
Expand All @@ -50,14 +52,28 @@ final class EditVideoViewController: NSViewController {
maxWidth: 300
)

private var loopCount: Int {
/*
Looping values are:
-1 | No loops
0 | Loop forever
>=1 | Loop n times
*/
guard Defaults[.loopGif] else {
return Int(loopCountTextField.intValue) == 0 ? -1 : Int(loopCountTextField.intValue)
}

return 0
}

private var conversionSettings: Gifski.Conversion {
.init(
video: inputUrl,
timeRange: timeRange,
quality: Defaults[.outputQuality],
dimensions: resizableDimensions.changed(dimensionsType: .pixels).currentDimensions.value,
frameRate: frameRateSlider.integerValue,
loopGif: Defaults[.loopGif]
loopCount: loopCount
)
}

Expand Down Expand Up @@ -97,6 +113,7 @@ final class EditVideoViewController: NSViewController {
setUpDropdowns()
setUpSliders()
setUpWidthAndHeightTextFields()
setUpLoopCountControls()
setUpDropView()
setUpTrimmingView()
}
Expand Down Expand Up @@ -282,6 +299,20 @@ final class EditVideoViewController: NSViewController {
}
}

private func showConversionCompletedAnimationWarningIfNeeded() {
// TODO: This function can be removed once NSImageView respects the looping counter in the GIF header.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you mirror the FB you submitted to Apple over at https://github.com/feedback-assistant/reports (follow the template) and then link to it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and thank you! I didn't know this resource existed.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is now outdated. The code should not be removed when it's fixed as it also applies to Quick Look. Rather the text should be modified to only mention Quick Look when it's fixed.

// https://github.com/feedback-assistant/reports/issues/187
SSApp.runOnce(identifier: "gifLoopCountWarning") {
DispatchQueue.main.async { [self] in
NSAlert.showModal(
for: view.window,
message: "Animated GIF Preview Limitation",
informativeText: "The after conversion preview and Quick Look will may not loop as expect, but the exorted file is valid."
Copy link
Owner

@sindresorhus sindresorhus Dec 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 3 typos in this text. I think it also could be more explicit about in what case it may not loop as expected. Try to spend some more effort on the text.

)
}
}
}

private func setUpWidthAndHeightTextFields() {
widthTextField.onBlur = { [weak self] width in
self?.resizableDimensions.resize(usingWidth: CGFloat(width))
Expand Down Expand Up @@ -314,6 +345,63 @@ final class EditVideoViewController: NSViewController {
updateTextFieldsMinMax()
}

private func setUpLoopCountControls() {
loopCountTextField.onBlur = { [weak self] loopCount in
guard let self = self else {
return
}

self.loopCountTextField.stringValue = "\(loopCount)"
self.loopCountStepper.intValue = Int32(loopCount)

if loopCount > 0 {
self.loopCheckbox.state = .off
}
}

loopCountTextField.onValueChange = { [weak self] loopCount in
guard let self = self else {
return
}

let validLoopCount = loopCount.clamped(to: Constants.loopCountRange)
self.loopCountTextField.stringValue = "\(validLoopCount)"
self.loopCountStepper.intValue = Int32(validLoopCount)

if validLoopCount > 0 {
self.loopCheckbox.state = .off
}
}

loopCheckbox.onAction = { [weak self] _ in
guard let self = self else {
return
}

if self.loopCheckbox.state == .on {
self.loopCountTextField.stringValue = "0"
self.loopCountStepper.intValue = 0
} else {
self.showConversionCompletedAnimationWarningIfNeeded()
}
}

Defaults.observe(.loopGif) { [weak self] in
self?.loopCountTextField.isEnabled = $0.newValue == false
self?.loopCountStepper.isEnabled = $0.newValue == false
}
.tieToLifetime(of: self)


loopCountStepper.onAction = { [weak self] _ in
guard let self = self else {
return
}

self.loopCountTextField.stringValue = "\(self.loopCountStepper.intValue)"
}
}

private func setUpDropView() {
let videoDropController = VideoDropViewController(dropLabelIsHidden: true)
add(childController: videoDropController)
Expand Down Expand Up @@ -342,7 +430,8 @@ final class EditVideoViewController: NSViewController {
heightTextField.nextKeyView = dimensionsTypeDropdown
dimensionsTypeDropdown.nextKeyView = frameRateSlider
frameRateSlider.nextKeyView = qualitySlider
qualitySlider.nextKeyView = loopCheckbox
qualitySlider.nextKeyView = loopCountTextField
loopCountTextField.nextKeyView = loopCheckbox
loopCheckbox.nextKeyView = cancelButton
}

Expand All @@ -351,6 +440,7 @@ final class EditVideoViewController: NSViewController {
let heightMinMax = resizableDimensions.heightMinMax
widthTextField.minMax = Int(widthMinMax.lowerBound)...Int(widthMinMax.upperBound)
heightTextField.minMax = Int(heightMinMax.lowerBound)...Int(heightMinMax.upperBound)
loopCountTextField.minMax = Constants.loopCountRange
}

private func dimensionsUpdated() {
Expand Down
Loading