Skip to content
Snippets Groups Projects
Select Git revision
  • sdtblck
  • master default protected
  • skyflynil
  • selfattention
  • fp16
  • swarm
  • tpu
7 results

test_nvcc.cu

Blame
  • backtransfer_notes.py 4.23 KiB
    import os
    import pickle
    from simfile.notes import NoteData
    from simfile.notes.count import *
    import simfile
    import torch
    from simfile.notes import Note, NoteType, NoteData
    from simfile.timing import Beat
    
    # test load file
    # decode whole chart
    # maybe change up and downs, right lefts/mirror
    # encode whole chart
    # write back
    from preprocess import process_chart
    
    test_file = 'C:/Users/cassi/OneDrive/Desktop/Master_Thesis/testing_sm_overwriting/test_pack/pkg1/110/110.sm'
    #test_file_2 = 'C:/Users/cassi/OneDrive/Desktop/Master_Thesis/testing_sm_overwriting/test_pack/pkg1/110/110.ssc'
    save_dir = 'C:/Users/cassi/OneDrive/Desktop/Master_Thesis/testing_sm_overwriting/test_pack/pkg_generated/110/'
    save_file = f'{save_dir}110 (edit).sm'
    #save_file_2 = f'{save_dir}110 (edit).ssc'
    
    os.makedirs(save_dir, exist_ok=True)
    # indexed_vocabulary_path = 'C:/Users/cassi/OneDrive/Desktop/Master_Thesis/test_cluster/vocabulary.pkl'
    #
    # opened_file = simfile.open(f"{test_file}")
    #
    # with open(f"{test_file}", 'r', encoding="ISO-8859-1") as infile:
    #     sm_file = simfile.load(infile)
    #
    # with open(f'{indexed_vocabulary_path}', 'rb') as fp:
    #     indexed_vocabulary = pickle.load(fp)
    #
    # charts = sm_file.charts
    # # get difficulty
    # difficulties = []
    # # sample notes over time, return list of NoteData and [] if empy (for now)
    # converted_charts = []
    # charts_per_song = len(charts)
    # device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
    # max_len_charts = 0
    #
    # for i, chart in enumerate(charts):
    #     notes_per_time = process_chart(opened_file, sm_file, chart, indexed_vocabulary, device)
    #     difficulty = chart.meter
    #     difficulties.append(int(difficulty))
    #     if max_len_charts < len(notes_per_time):
    #         max_len_charts = len(notes_per_time)
    #     converted_charts.append(notes_per_time)
    #
    # assert (len(converted_charts) == len(difficulties))
    #
    # # chart = sm_file.charts[0]
    # for chart in charts:
    #     note_data = NoteData(chart)
    #     cols = note_data.columns
    #
    #     def mirror(note, cols):
    #         return Note(
    #             beat=note.beat,
    #             column=cols - note.column - 1,
    #             note_type=note.note_type,
    #         )
    #
    #     mirrored_notes = (mirror(note, cols) for note in note_data)
    #     mirrored_note_data = NoteData.from_notes(mirrored_notes, cols)
    #     chart.notes = str(mirrored_note_data)
    #
    # save_sm_file = sm_file.copy()
    # save_sm_file.charts = charts
    
    # with simfile.mutate(
    #     test_file,
    #     backup_filename=f'{test_file}.old',
    # ) as sm_file:
    #     charts = sm_file.charts
    #
    #     for chart in charts:
    #         note_data = NoteData(chart)
    #         cols = note_data.columns
    #
    #         def mirror(note, cols):
    #             return Note(
    #                 beat=note.beat,
    #                 column=cols - note.column - 1,
    #                 note_type=note.note_type,
    #             )
    #
    #
    #         mirrored_notes = (mirror(note, cols) for note in note_data)
    #         mirrored_note_data = NoteData.from_notes(mirrored_notes, cols)
    #         chart.notes = str(mirrored_note_data)
    #     sm_file.charts = charts
    #     sm_file.subtitle += '(edited)'
    
    sm_file = simfile.open(test_file, strict=False)
    charts = sm_file.charts
    #print(charts)
    sm_file.subtitle = '(edited)'
    new_charts = ''
    #sm_file.title = sm_file.title + '(edited)'
    
    print("Original first chart notes:")
    print(sm_file.charts[0].notes[100:200])
    
    for i, chart in enumerate(charts):
        note_data = NoteData(chart)
        cols = note_data.columns
    
        def mirror(note, cols):
            return Note(
                beat=note.beat,
                column=cols - note.column - 1,
                note_type=note.note_type,
            )
    
        mirrored_notes = (mirror(note, cols) for note in note_data)
        mirrored_note_data = NoteData.from_notes(mirrored_notes, cols)
        sm_file.charts[i].notes = str(mirrored_note_data)
    
    print("Updated first chart notes:")
    print(sm_file.charts[0].notes[100:200])
    
    with open(f'{save_file}', 'w', encoding='utf-8') as outfile:
        sm_file.serialize(outfile)
    
    
    new_sm_file = simfile.open(save_file, strict=False)
    print("\n Loaded new first chart notes:")
    print(new_sm_file.charts[0].notes[100:200])
    
    # cols = 4
    # notes = [
    #     Note(beat=Beat(i, 2), column=i%cols, note_type=NoteType.TAP)
    #     for i in range(8)
    # ]
    #
    # note_data = NoteData.from_notes(notes, cols)
    #
    # print(str(note_data))