Skip to content

Commit

Permalink
some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Oct 12, 2024
1 parent 1946364 commit 27c0117
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 41 deletions.
4 changes: 2 additions & 2 deletions source/funkin/InitState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import funkin.data.freeplay.album.AlbumRegistry;
import funkin.data.freeplay.player.PlayerRegistry;
import funkin.data.freeplay.style.FreeplayStyleRegistry;
import funkin.data.notestyle.NoteStyleRegistry;
import funkin.data.charting.GenerateOperatorRegistry;
import funkin.data.charting.GenerateChartOperatorRegistry;
import funkin.data.song.SongRegistry;
import funkin.data.event.SongEventRegistry;
import funkin.data.stage.StageRegistry;
Expand Down Expand Up @@ -167,7 +167,7 @@ class InitState extends FlxState
trace('Parsing game data...');
var perfStart:Float = TimerUtil.start();
SongEventRegistry.loadEventCache(); // SongEventRegistry is structured differently so it's not a BaseRegistry.
GenerateOperatorRegistry.instance.loadEntries();
GenerateChartOperatorRegistry.instance.loadEntries();
SongRegistry.instance.loadEntries();
LevelRegistry.instance.loadEntries();
NoteStyleRegistry.instance.loadEntries();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@ import funkin.data.BaseClassRegistry;
import funkin.ui.debug.charting.util.GenerateChartOperator;

@:build(funkin.util.macro.ClassRegistryMacro.build())
class GenerateOperatorRegistry extends BaseClassRegistry<GenerateChartOperator>
class GenerateChartOperatorRegistry extends BaseClassRegistry<GenerateChartOperator>
{
public function new()
{
super('generateChartOperatorRegistry');

for (entry in entries.values())
{
trace(entry.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package funkin.ui.debug.charting.handlers;

import funkin.ui.debug.charting.commands.GenerateNotesCommand;
import funkin.ui.debug.charting.ChartEditorState;
import funkin.data.charting.GenerateChartOperatorRegistry;
import funkin.data.song.SongData;
import funkin.util.SortUtil;
import funkin.util.FileUtil;
Expand All @@ -27,7 +28,7 @@ class ChartEditorChartGeneratorHandler
*/
public static function generateChartFromMidi(state:ChartEditorState, params:ChartGeneratorHintParams):Void
{
var hints:Array<SongNoteData> = [];
var data:Array<NoteMidiData> = [];

var bpm:Float = 0;
for (track in params.midi.tracks)
Expand Down Expand Up @@ -60,26 +61,30 @@ class ChartEditorChartGeneratorHandler
case MidiMessage(e):
if (e.midiMessage.messageType == MessageType.NoteOn)
{
// byte 2 = note
var data:Int = (e.midiMessage.byte2 % 4) + (channel.isPlayerTrack ? 0 : 4);
var time:Float = translateToMS(event.absoluteTime, bpm, params.midi.timeDivision);
hints.push(new SongNoteData(time, data, 0));
data.push(
{
note: e.midiMessage.byte2,
time: time,
length: 0,
isPlayerNote: channel.isPlayerTrack
});
}
else if (e.midiMessage.messageType == MessageType.NoteOff)
{
if (hints.length == 0)
if (data.length == 0)
{
continue;
}

var currentHint:SongNoteData = hints[hints.length - 1];
var curData:NoteMidiData = data[data.length - 1];
var threshold:Float = (60.0 / bpm) * 1000.0 * 0.25;
var sustainLength:Float = translateToMS(event.absoluteTime, bpm, params.midi.timeDivision);
sustainLength -= currentHint.time;
sustainLength -= curData.time;
sustainLength -= threshold;
if (sustainLength > 0.001)
{
currentHint.length = sustainLength;
curData.length = sustainLength;
}
}
default:
Expand All @@ -88,9 +93,10 @@ class ChartEditorChartGeneratorHandler
}
}

hints.sort(SortUtil.noteDataByTime.bind(FlxSort.ASCENDING));
data.sort((a, b) -> FlxSort.byValues(FlxSort.ASCENDING, a.time, b.time));
var notes:Array<SongNoteData> = GenerateChartOperatorRegistry.instance.fetchEntries()[0].execute(data);

state.performCommand(new GenerateNotesCommand(params.onlyHints ? null : hints, hints, null));
state.performCommand(new GenerateNotesCommand(params.onlyHints ? null : notes, notes, null));
}

/**
Expand Down Expand Up @@ -208,6 +214,8 @@ typedef NoteMidiData =
{
var note:Int;
var time:Float;
var length:Float;
var isPlayerNote:Bool;
}

typedef ChartGeneratorHintParams =
Expand Down
42 changes: 19 additions & 23 deletions source/funkin/ui/debug/charting/util/ChartEditorDropdowns.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import haxe.ui.components.DropDown;
import funkin.play.stage.Stage;
import funkin.play.character.BaseCharacter.CharacterType;
import funkin.data.event.SongEventRegistry;
import funkin.data.charting.GenerateOperatorRegistry;
import funkin.data.charting.GenerateChartOperatorRegistry;
import funkin.play.character.CharacterData.CharacterDataParser;

/**
Expand Down Expand Up @@ -246,28 +246,24 @@ class ChartEditorDropdowns
return returnValue;
}

// public static function populateDropdownWithGenerateChartOperators(dropDown:DropDown):DropDownEntry
// {
// dropDown.dataSource.clear();
// for (op in GenerateChartOperatorRegistry.listOperators())
// {
// var value:DropDownEntry = {id: op.id, text: op.name};
// dropDown.dataSource.add(value);
// }
// dropDown.dataSource.sort('text', ASCENDING);
// return dropDown.dataSource.get(0);
// }
// public static function populateDropdownWithGenerateDifficultyOperators(dropDown:DropDown):DropDownEntry
// {
// dropDown.dataSource.clear();
// for (op in GenerateDifficultyOperatorRegistry.listOperators())
// {
// var value:DropDownEntry = {id: op.id, text: op.name};
// dropDown.dataSource.add(value);
// }
// dropDown.dataSource.sort('text', ASCENDING);
// return dropDown.dataSource.get(0);
// }
public static function populateDropdownWithGenerateChartOperators(dropDown:DropDown, startingOperatorId:String):DropDownEntry
{
var data:DropDownEntry = null;
dropDown.dataSource.clear();
for (op in GenerateChartOperatorRegistry.fetchEntries())
{
var value:DropDownEntry = {id: op.id, text: op.name};
dropDown.dataSource.add(value);
if (op.id == startingOperatorId)
{
data = value;
}
}
dropDown.dataSource.sort('text', ASCENDING);
data = data ?? dropDown.dataSource.get(0);
dropDown.value = data;
return data;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
package funkin.ui.debug.charting.util;

import funkin.data.song.SongData;
import haxe.ui.containers.VBox;

class DefaultGenerateChartOperator extends GenerateChartOperator
{
public function new()
{
super('defaultGenerateChartOperator', 'Default Algorithm');
}

/**
* Creates the chart
* @param data The note data
* @return The notes to generate
*/
override public function execute(data:Array<NoteMidiData>):Array<SongNoteData>
{
var notes:Array<SongNoteData> = [];
for (d in data)
{
notes.push(new SongNoteData(d.time, d.note % 4 + (d.isPlayerNote ? 0 : 4), d.length));
}
return notes;
}

/**
* Builds the haxe ui
* @param root The root to add the components to
*/
override public function buildUI(root:VBox):Void {}
}

0 comments on commit 27c0117

Please sign in to comment.