Skip to content

Commit

Permalink
Enable empty lines in environments
Browse files Browse the repository at this point in the history
  • Loading branch information
Desbeers committed Oct 28, 2023
1 parent c7baf0f commit ac4c84b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 24 deletions.
17 changes: 9 additions & 8 deletions Chord Provider/ChordProParser/ChordPro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,19 @@ enum ChordPro {
}
case "":
/// Empty line; close the section if it has an 'automatic type',
/// else close the section and start a new one with the same label and type
/// else add an empty line in the section
if !currentSection.lines.isEmpty {
if currentSection.autoType {
if currentSection.type == .none || currentSection.autoType {
song.sections.append(currentSection)
currentSection = Song.Section(id: song.sections.count + 1)
} else {
song.sections.append(currentSection)
currentSection = Song.Section(
id: song.sections.count + 1,
label: currentSection.label,
type: currentSection.type
)
/// Start with a fresh line:
var line = Song.Section.Line(id: currentSection.lines.count + 1)
/// Add an empty part
/// - Note: Use a 'space' as text
var part = Song.Section.Line.Part(id: 1, chord: nil, text: " ")
line.parts.append(part)
currentSection.lines.append(line)
}
}
case "#":
Expand Down
Binary file modified Chord Provider/Metronome/Low.aif
Binary file not shown.
2 changes: 1 addition & 1 deletion Chord Provider/Metronome/Metronome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class Metronome: ObservableObject {
}
}
/// Bool for the high/low tick and animation
@Published var flip: Bool = false
@Published var flip: Bool = true
/// Timing for the next 'tick'
private var nextTick: DispatchTime = DispatchTime.distantFuture
/// The ID of the 'low' sound
Expand Down
31 changes: 21 additions & 10 deletions Chord Provider/SongModel/Song+Render/Song+Render.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extension Song.Render {
/// The display options
let options: Song.DisplayOptions
/// The optional label
var label: String?
var label: String = ""
/// Bool if the section is prominent (chorus for example)
var prominent: Bool = false

Expand All @@ -96,7 +96,10 @@ extension Song.Render {
switch options.label {
case .inline:
VStack(alignment: .leading) {
if let label {
if label.isEmpty {
content
.padding(.leading)
} else {
switch prominent {
case true:
ProminentLabel(options: options, label: label)
Expand All @@ -106,15 +109,12 @@ extension Song.Render {
Divider()
content
.padding(.leading)
} else {
content
.padding(.leading)
}
}
.padding(.top)
case .grid:
GridRow {
Text(label ?? " ")
Text(label)
.padding(.all, prominent ? 10 : 0)
.background(prominent ? Color.accentColor.opacity(0.3) : Color.clear, in: RoundedRectangle(cornerRadius: 4))
.frame(minWidth: 100, alignment: .trailing)
Expand All @@ -125,7 +125,7 @@ extension Song.Render {
Rectangle()
.frame(width: 1, height: nil, alignment: .leading)
.foregroundColor(
prominent || label != nil ? Color.secondary.opacity(0.3) : Color.clear), alignment: .leading
prominent || label.isEmpty ? Color.clear : Color.secondary.opacity(0.3)), alignment: .leading
)
.gridColumnAlignment(.leading)
}
Expand Down Expand Up @@ -179,7 +179,13 @@ extension Song.Render {
}
}
}
.modifier(SectionView(options: options, label: section.label ?? "Chorus", prominent: true))
.modifier(
SectionView(
options: options,
label: section.label.isEmpty ? "Chorus" : section.label,
prominent: true
)
)
}
}

Expand All @@ -191,8 +197,12 @@ extension Song.Render {
let options: Song.DisplayOptions
/// The body of the `View`
var body: some View {
ProminentLabel(options: options, label: section.label ?? "Repeat Chorus", icon: "arrow.triangle.2.circlepath")
.modifier(SectionView(options: options))
ProminentLabel(
options: options,
label: section.label.isEmpty ? "Repeat Chorus" : section.label,
icon: "arrow.triangle.2.circlepath"
)
.modifier(SectionView(options: options))
}
}

Expand Down Expand Up @@ -335,6 +345,7 @@ extension Song.Render {
}
}
}
.frame(maxWidth: 400 * options.scale, alignment: .leading)
.modifier(SectionView(options: options, label: section.label))
}
}
Expand Down
2 changes: 1 addition & 1 deletion Chord Provider/SongModel/Song+Section.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension Song {
/// The unique ID
var id: Int
/// The optional label of the section
var label: String?
var label: String = ""
/// The `Environment type` of the section
var type: ChordPro.Environment = .none
/// Bool if the Environment is automatic set or not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ extension EditorView {
}
}
.labelsHidden()
#if os(macOS)
.frame(maxWidth: 75)
#endif
}
.menuStyle(.button)
}
Expand Down
12 changes: 8 additions & 4 deletions Chord Provider/Views/HeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ struct HeaderView: View {
HStack(alignment: .center) {
General(song: sceneState.song)
Details(song: sceneState.song)
if let tempo = sceneState.song.tempo, let bpm = Float(tempo) {
MetronomeView(bpm: bpm)
.padding(.leading)
}
ToolbarView.PlayerButtons()
}
.frame(maxWidth: .infinity)
Expand All @@ -36,6 +40,10 @@ struct HeaderView: View {
General(song: sceneState.song)
Details(song: sceneState.song)
.labelStyle(.titleAndIcon)
if let tempo = sceneState.song.tempo, let bpm = Float(tempo) {
MetronomeView(bpm: bpm)
.padding(.leading)
}
#elseif os(visionOS)
Details(song: sceneState.song)
.labelStyle(.titleAndIcon)
Expand Down Expand Up @@ -91,10 +99,6 @@ extension HeaderView {
if let time = song.time {
Label(time, systemImage: "timer").padding(.leading)
}
if let tempo = song.tempo, let bpm = Float(tempo) {
MetronomeView(bpm: bpm)
.padding(.leading)
}
}
}
}

0 comments on commit ac4c84b

Please sign in to comment.