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

pass in chorus style to processline #26

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
13 changes: 8 additions & 5 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -127,7 +127,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -171,10 +171,12 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand All @@ -185,6 +187,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -272,7 +275,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -346,7 +349,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -395,7 +398,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 2 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
17 changes: 17 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,23 @@ class _HomePageState extends State<HomePage> {
[Am]As we lose our, [G]inhibition
[C]Celebration, [F]its around us
[Am]Every nation, [G]all around us
{soc}
[C]Singing forever [F]young,
Singing [Am]songs underneath the sun[G]
Let's [C]rejoice in the beautiful game[F]
And [Am]together, every end of the day[G]
{eoc}
[C]When I get older, [F]I will be stronger
[Am]They'll call me freedom, [G]just like a waving [C]flag
And then it goes [F]back, and then it goes [Am]back
And then it goes [G]back , and then it goes …
{soc}
We all say
[C]When I get older, [F]I will be stronger
[Am]They'll call me freedom, [G]just like a waving [C]flag
And then it goes [F]back, and then it goes [Am]back
And then it goes [G]back , and then it goes …
{eoc}
''';
}
}
17 changes: 13 additions & 4 deletions lib/src/chord_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ChordProcessor {
required String text,
required TextStyle lyricsStyle,
required TextStyle chordStyle,
required TextStyle chorusStyle,
double scaleFactor = 1.0,
int widgetPadding = 0,
int transposeIncrement = 0,
Expand Down Expand Up @@ -58,7 +59,7 @@ class ChordProcessor {

List<ChordLyricsLine> _chordLyricsLines = newLines
.map<ChordLyricsLine>(
(line) => _processLine(line, lyricsStyle, chordStyle))
(line) => _processLine(line, lyricsStyle, chordStyle, chorusStyle))
.toList();

return ChordLyricsDocument(_chordLyricsLines,
Expand Down Expand Up @@ -125,15 +126,23 @@ class ChordProcessor {
.width;
}

ChordLyricsLine _processLine(
String line, TextStyle lyricsStyle, TextStyle chordStyle) {
bool isChorus = false;
ChordLyricsLine _processLine(String line, TextStyle lyricsStyle,
TextStyle chordStyle, TextStyle chorusStyle) {
ChordLyricsLine _chordLyricsLine = ChordLyricsLine();
String _lyricsSoFar = '';
String _chordsSoFar = '';
bool _chordHasStarted = false;
if (line.contains("{soc}") || line.contains("{start_of_chorus}")) {
isChorus = true;
} else if (line.contains("{eoc}") || line.contains("{end_of_chorus}")) {
isChorus = false;
}
line.split('').forEach((character) {
if (character == ']') {
final sizeOfLeadingLyrics = textWidth(_lyricsSoFar, lyricsStyle);
final sizeOfLeadingLyrics = isChorus
? textWidth(_lyricsSoFar, chorusStyle)
: textWidth(_lyricsSoFar, lyricsStyle);

final lastChordText = _chordLyricsLine.chords.isNotEmpty
? _chordLyricsLine.chords.last.chordText
Expand Down
1 change: 1 addition & 0 deletions lib/src/lyrics_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class _LyricsRendererState extends State<LyricsRenderer> {
text: widget.lyrics,
lyricsStyle: widget.textStyle,
chordStyle: widget.chordStyle,
chorusStyle: chorusStyle,
widgetPadding: widget.widgetPadding,
scaleFactor: widget.scaleFactor,
transposeIncrement: widget.transposeIncrement,
Expand Down
24 changes: 17 additions & 7 deletions test/chord_processor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void main() {
text: text,
lyricsStyle: textStyle,
chordStyle: textStyle,
chorusStyle: textStyle,
);

expect(
Expand Down Expand Up @@ -58,19 +59,22 @@ void main() {
MaterialApp(
builder: (context, _) {
String text =
'[C]This is t[D]he lyrics[E]\n[A]This is t[D]he se[B]cond line[E]';
'{soc}\n[C]This is t[D]he Cho[D]rus\n{eoc}\n[C]This is t[D]he lyrics[E]\n[A]This is t[D]he se[B]cond line[E]';
final textStyle = TextStyle(fontSize: 18, color: Colors.green);
final chorusStyle = TextStyle(
fontSize: 21, fontWeight: FontWeight.bold, color: Colors.white);

final processor = ChordProcessor(context);
final chordDocument = processor.processText(
text: text,
lyricsStyle: textStyle,
chordStyle: textStyle,
chorusStyle: chorusStyle,
);

expect(
chordDocument.chordLyricsLines.length,
2,
5,
);
expect(
chordDocument.chordLyricsLines.last.chords.length,
Expand All @@ -81,23 +85,27 @@ void main() {
'E',
);
expect(
chordDocument.chordLyricsLines.first.chords.first.leadingSpace,
chordDocument.chordLyricsLines[1].chords.first.leadingSpace,
0.0,
);

expect(
chordDocument.chordLyricsLines.first.chords[1].chordText,
chordDocument.chordLyricsLines[1].chords[1].chordText,
'D',
);

final textWidth = processor.textWidth('This is t', textStyle);
final chordWidth = processor.textWidth('C', textStyle);
expect(
chordDocument.chordLyricsLines.first.chords[1].leadingSpace,
chordDocument.chordLyricsLines[3].chords[1].leadingSpace,
textWidth - chordWidth,
);

// The builder function must return a widget.
final chorusTextWidth = processor.textWidth('This is t', chorusStyle);
final chorusChordWidth = processor.textWidth('C', textStyle);
expect(
chordDocument.chordLyricsLines[1].chords[1].leadingSpace,
chorusTextWidth - chorusChordWidth,
); // The builder function must return a widget.
return Container();
},
),
Expand All @@ -118,6 +126,7 @@ void main() {
text: text,
lyricsStyle: textStyle,
chordStyle: textStyle,
chorusStyle: textStyle,
);

expect(chordDocument.capo, 3);
Expand Down Expand Up @@ -174,6 +183,7 @@ void main() {
text: text,
lyricsStyle: textStyle,
chordStyle: textStyle,
chorusStyle: textStyle,
);

expect(
Expand Down
Loading