-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
425 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,77 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:lyric/data/database.dart'; | ||
import 'package:lyric/data/song/song.dart'; | ||
import 'package:lyric/ui/base/songs/filter/key/state.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
part 'filter.g.dart'; | ||
|
||
typedef KeyFilterSelectable = ({String label, Function(bool) onSelected, bool selected, bool addingKey}); | ||
|
||
@Riverpod(keepAlive: true) | ||
Future<List<String>> selectableKeyRootsFor(Ref ref, {String? mode}) { | ||
throw UnimplementedError(); | ||
Stream<List<KeyFilterSelectable>> selectablePitches(Ref ref) { | ||
final state = ref.watch(keyFilterStateProvider); | ||
if (state.modes.length == 1 && state.pitches.isEmpty) { | ||
return db.selectDistinctPitches(state.modes.first).watch().map((pitches) { | ||
List<KeyFilterSelectable> selectables = []; | ||
for (var e in pitches) { | ||
final key = KeyField(e, state.modes.first); | ||
if (state.keys.contains(key)) continue; | ||
selectables.add(( | ||
label: key.toString(), | ||
onSelected: (v) => ref.read(keyFilterStateProvider.notifier).setKeyTo(key, v), | ||
selected: state.keys.contains(key), | ||
addingKey: true, | ||
)); | ||
} | ||
return selectables; | ||
}); | ||
} else { | ||
return db.selectDistinctPitches('%').watch().map((pitches) { | ||
return pitches | ||
.map( | ||
(e) => ( | ||
label: e, | ||
onSelected: (v) => ref.read(keyFilterStateProvider.notifier).setPitchTo(e, v), | ||
selected: state.pitches.contains(e), | ||
addingKey: false, | ||
), | ||
) | ||
.toList(); | ||
}); | ||
} | ||
} | ||
|
||
@Riverpod(keepAlive: true) | ||
Future<List<String>> selectableKeyModesFor(Ref ref, {String? root}) { | ||
throw UnimplementedError(); | ||
Stream<List<KeyFilterSelectable>> selectableModes(Ref ref) { | ||
final state = ref.watch(keyFilterStateProvider); | ||
if (state.pitches.length == 1 && state.modes.isEmpty) { | ||
return db.selectDistinctModes(state.pitches.first).watch().map((modes) { | ||
List<KeyFilterSelectable> selectables = []; | ||
for (var e in modes) { | ||
final key = KeyField(state.pitches.first, e); | ||
if (state.keys.contains(key)) continue; | ||
selectables.add(( | ||
label: key.toString(), | ||
onSelected: (v) => ref.read(keyFilterStateProvider.notifier).setKeyTo(key, v), | ||
selected: state.keys.contains(key), | ||
addingKey: true, | ||
)); | ||
} | ||
return selectables; | ||
}); | ||
} else { | ||
return db.selectDistinctModes('%').watch().map((modes) { | ||
return modes | ||
.map( | ||
(e) => ( | ||
label: e, | ||
onSelected: (v) => ref.read(keyFilterStateProvider.notifier).setModeTo(e, v), | ||
selected: state.modes.contains(e), | ||
addingKey: false, | ||
), | ||
) | ||
.toList(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import '../../data/song/song.drift'; | ||
import '../../data/song/song.dart'; | ||
|
||
selectDistinctKeys: | ||
SELECT DISTINCT | ||
key_field | ||
FROM songs; | ||
|
||
selectDistinctPitches(:for_mode AS TEXT): | ||
SELECT DISTINCT | ||
substr( | ||
key_field | ||
,1 | ||
,instr(key_field, '-') - 1 | ||
) | ||
FROM songs | ||
WHERE key_field != '' AND key_field LIKE concat('%-', :for_mode); | ||
|
||
selectDistinctModes(:for_pitch AS TEXT): | ||
SELECT DISTINCT | ||
substr( | ||
key_field | ||
,instr(key_field, '-') + 1 | ||
) | ||
FROM songs | ||
WHERE key_field != '' AND key_field LIKE concat(:for_pitch, '-%'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.