Home > OS >  Changing notes position based on new bpm
Changing notes position based on new bpm

Time:12-02

I have a .mboy json file that are build with bpm 128 which is the audio original bpm.

have a look below at the file.

 export default {
"editor": "mboy-editor-2.1.1",
"format_version": "2.0",
"audio": {
    "artist": "test",
    "title": "NO COPYRIGHT SHORT MUSIC (SOLO RECORD)",
    "album": "",
    "subgenre": "",
    "date": "",
    "download_link": "https://www.youtube.com/watch?v=Atv-zwhSyFE",
    "comments": "",
    "genre": "Other"
},
"author": "<zx<zx",
"date": "2022-11-17",
"tempo": 128,
"start_pos": 0,
"tracks": [{
    "instrument": "bass",
    "name": "",
    "color": "ff009fff",
    "bars": [{
        "index": 0,
        "quarters_count": 4,
        "notes": [{
            "pos": 400,
            "len": 100,
            "markers": []
        }, {
            "pos": 800,
            "len": 100,
            "markers": []
        }, {
            "pos": 1100,
            "len": 100,
            "markers": []
        }, {
            "pos": 1200,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 1,
        "quarters_count": 4,
        "notes": [{
            "pos": 100,
            "len": 100,
            "markers": []
        }, {
            "pos": 1000,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 2,
        "quarters_count": 4,
        "notes": [{
            "pos": 100,
            "len": 100,
            "markers": []
        }, {
            "pos": 900,
            "len": 100,
            "markers": []
        }, {
            "pos": 1400,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 3,
        "quarters_count": 4,
        "notes": [{
            "pos": 1000,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 4,
        "quarters_count": 4,
        "notes": [{
            "pos": 200,
            "len": 100,
            "markers": []
        }, {
            "pos": 1200,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 5,
        "quarters_count": 4,
        "notes": [{
            "pos": 100,
            "len": 100,
            "markers": []
        }, {
            "pos": 900,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 6,
        "quarters_count": 4,
        "notes": [{
            "pos": 300,
            "len": 100,
            "markers": []
        }, {
            "pos": 500,
            "len": 100,
            "markers": []
        }, {
            "pos": 1200,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 7,
        "quarters_count": 4,
        "notes": [{
            "pos": 400,
            "len": 100,
            "markers": []
        }, {
            "pos": 500,
            "len": 100,
            "markers": []
        }, {
            "pos": 900,
            "len": 100,
            "markers": []
        }, {
            "pos": 1400,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 8,
        "quarters_count": 4,
        "notes": [{
            "pos": 400,
            "len": 100,
            "markers": []
        }, {
            "pos": 500,
            "len": 100,
            "markers": []
        }, {
            "pos": 700,
            "len": 100,
            "markers": []
        }, {
            "pos": 1300,
            "len": 100,
            "markers": []
        }, {
            "pos": 1400,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 9,
        "quarters_count": 4,
        "notes": [{
            "pos": 100,
            "len": 100,
            "markers": []
        }, {
            "pos": 700,
            "len": 100,
            "markers": []
        }, {
            "pos": 1300,
            "len": 100,
            "markers": []
        }, {
            "pos": 1500,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 10,
        "quarters_count": 4,
        "notes": [{
            "pos": 500,
            "len": 100,
            "markers": []
        }, {
            "pos": 700,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 11,
        "quarters_count": 4,
        "notes": [{
            "pos": 900,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 12,
        "quarters_count": 4,
        "notes": [{
            "pos": 0,
            "len": 100,
            "markers": []
        }, {
            "pos": 1400,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 13,
        "quarters_count": 4,
        "notes": [{
            "pos": 0,
            "len": 100,
            "markers": []
        }, {
            "pos": 1200,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 14,
        "quarters_count": 4,
        "notes": [{
            "pos": 800,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 15,
        "quarters_count": 4,
        "notes": [{
            "pos": 200,
            "len": 100,
            "markers": []
        }, {
            "pos": 1000,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 16,
        "quarters_count": 4,
        "notes": []
    }, {
        "index": 17,
        "quarters_count": 4,
        "notes": [{
            "pos": 500,
            "len": 100,
            "markers": ["ToLeft"]
        }
        ]
    }, {
        "index": 18,
        "quarters_count": 4,
        "notes": []
    }, {
        "index": 19,
        "quarters_count": 4,
        "notes": []
    }, {
        "index": 20,
        "quarters_count": 4,
        "notes": []
    }
    ]
}, {
    "instrument": "drums",
    "name": "",
    "color": "ff009fff",
    "bars": [{
        "index": 0,
        "quarters_count": 4,
        "notes": [{
            "pos": 400,
            "len": 100,
            "markers": []
        }, {
            "pos": 800,
            "len": 100,
            "markers": []
        }, {
            "pos": 1400,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 1,
        "quarters_count": 4,
        "notes": [{
            "pos": 800,
            "len": 100,
            "markers": []
        }, {
            "pos": 1300,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 2,
        "quarters_count": 4,
        "notes": [{
            "pos": 100,
            "len": 100,
            "markers": []
        }, {
            "pos": 500,
            "len": 100,
            "markers": []
        }, {
            "pos": 900,
            "len": 100,
            "markers": []
        }, {
            "pos": 1400,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 3,
        "quarters_count": 4,
        "notes": [{
            "pos": 100,
            "len": 100,
            "markers": []
        }, {
            "pos": 500,
            "len": 100,
            "markers": []
        }, {
            "pos": 1000,
            "len": 100,
            "markers": []
        }, {
            "pos": 1300,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 4,
        "quarters_count": 4,
        "notes": [{
            "pos": 200,
            "len": 100,
            "markers": []
        }, {
            "pos": 600,
            "len": 100,
            "markers": []
        }, {
            "pos": 1000,
            "len": 100,
            "markers": []
        }, {
            "pos": 1500,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 5,
        "quarters_count": 4,
        "notes": [{
            "pos": 200,
            "len": 100,
            "markers": []
        }, {
            "pos": 400,
            "len": 100,
            "markers": []
        }, {
            "pos": 1100,
            "len": 100,
            "markers": []
        }, {
            "pos": 1200,
            "len": 100,
            "markers": []
        }, {
            "pos": 1400,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 6,
        "quarters_count": 4,
        "notes": [{
            "pos": 200,
            "len": 100,
            "markers": []
        }, {
            "pos": 400,
            "len": 100,
            "markers": []
        }, {
            "pos": 700,
            "len": 100,
            "markers": []
        }, {
            "pos": 900,
            "len": 100,
            "markers": []
        }, {
            "pos": 1400,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 7,
        "quarters_count": 4,
        "notes": [{
            "pos": 200,
            "len": 100,
            "markers": []
        }, {
            "pos": 600,
            "len": 100,
            "markers": []
        }, {
            "pos": 800,
            "len": 100,
            "markers": []
        }, {
            "pos": 1000,
            "len": 100,
            "markers": []
        }, {
            "pos": 1300,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 8,
        "quarters_count": 4,
        "notes": [{
            "pos": 200,
            "len": 100,
            "markers": []
        }, {
            "pos": 600,
            "len": 100,
            "markers": []
        }, {
            "pos": 900,
            "len": 100,
            "markers": []
        }, {
            "pos": 1100,
            "len": 100,
            "markers": []
        }, {
            "pos": 1300,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 9,
        "quarters_count": 4,
        "notes": [{
            "pos": 200,
            "len": 100,
            "markers": []
        }, {
            "pos": 500,
            "len": 100,
            "markers": []
        }, {
            "pos": 1100,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 10,
        "quarters_count": 4,
        "notes": [{
            "pos": 0,
            "len": 100,
            "markers": []
        }, {
            "pos": 100,
            "len": 100,
            "markers": []
        }, {
            "pos": 500,
            "len": 100,
            "markers": []
        }, {
            "pos": 900,
            "len": 100,
            "markers": []
        }, {
            "pos": 1000,
            "len": 100,
            "markers": []
        }, {
            "pos": 1300,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 11,
        "quarters_count": 4,
        "notes": [{
            "pos": 200,
            "len": 100,
            "markers": []
        }, {
            "pos": 500,
            "len": 100,
            "markers": []
        }, {
            "pos": 800,
            "len": 100,
            "markers": []
        }, {
            "pos": 1200,
            "len": 100,
            "markers": []
        }
        ]
    }, {
        "index": 12,
        "quarters_count": 4,
        "notes": [{
            "pos": 200,
            "len": 100,
            "markers": []
        }, {
            "pos": 400,
            "len": 100,
            "markers": []
        }, {
            "pos": 1100,
            "len": 100,
            "markers": []
        }
        ]
    }
    ]
}
],
"markers": [{
    "id": "extended",
    "code": "*",
    "color": "ffffff00"
}, {
    "id": "ToLeft",
    "code": "<",
    "color": "ffffff00"
}, {
    "id": "ToRight",
    "code": ">",
    "color": "ffffff00"
}
]
}

my game play just fine with the current file, but what I want is to make it slower and that mean I have to change the bpm from 128 to 240.

I have the current pos and len for the bpm 128.

I want to know if I can change the position of the notes based on the new bpm.

I do not want to change the audio file only the notes above so it can follow the new speed and still use the same audio file.

Update about mboy editor.

mboy editor is a free application for making charts for rythm games, here is the link https://vfpe.itch.io/mboy-editor. the pos is a position of the note in the chart where each bar represent 0 to 1500 in length, in it there is x notes. the next bar represent p n where n is the next bar notes and p is the previous length of the notes.

This below is the equation I came up with to write calculate the right pos of the notes

   const getYPosition = (mboyNote: any, bar: any, trackIndex: number) => {
            const q = bar.index * (bar.quarters_count * windowPropeties.noteHeight)
            let appender = (bar.index * 15 * (windowPropeties.noteHeight));
            let y = windowPropeties.height - (appender   mboyNote.pos   q);

            return y;
        }

CodePudding user response:

To update the positions of the notes in your .mboy file using JavaScript, you can use the following steps:

Parse the .mboy file to extract the positions of the notes. This will likely involve reading the file and using a JSON parser to convert the data into a JavaScript object that you can work with.

Calculate the difference in speed between the old BPM (128) and the new BPM (240). You can do this by dividing the new BPM by the old BPM to get a ratio of the speeds. For example, if the new BPM is twice as fast as the old BPM, the ratio will be 2.

Use the ratio of the speeds to update the positions of the notes in your .mboy file. You can do this by iterating over the notes and multiplying each position by the ratio. For example, if a note was originally at position 100 with BPM 128, and the new BPM is 240, you would multiply the position by 2 to get a new position of 200.

Save the updated .mboy file using the appropriate method for your file format. For example, if you are using JSON, you can use the JSON.stringify() method to convert the updated data back into a string that you can save to a file.

Here is an example of how you might implement these steps in JavaScript:

// Parse the .mboy file to extract the positions of the notes
const mboyData = JSON.parse(fs.readFileSync('myfile.mboy', 'utf8'));
const notes = mboyData.notes;

// Calculate the ratio of the speeds
const oldBpm = 128;
const newBpm = 240;
const speedRatio = newBpm / oldBpm;

// Update the positions of the notes using the speed ratio
for (const note of notes) {
  note.pos = note.pos * speedRatio;
}

// Save the updated .mboy file
fs.writeFileSync('myfile.mboy', JSON.stringify(mboyData));

Keep in mind that this is just an example, and you may need to adjust the code to fit the specific structure of your .mboy file.

CodePudding user response:

If you want to change the speed of your notes in a .mboy file without changing the speed of the audio, you can use the equation you provided to calculate the new position for each note based on the new BPM. The equation uses the original position of the note and the length of the previous bar to calculate the new position for the note in the new BPM.

You can loop through all of the notes in the .mboy file and use the equation to calculate the new position for each note. Then, you can update the position for each note in the file with the new calculated position. This should allow you to change the speed of the notes in the file without changing the speed of the audio.

To change the speed of the notes in a .mboy file without changing the speed of the audio, you will need to use the following equation:

new_position = original_position * (new_bpm / old_bpm)

This equation uses the original position of the note and the length of the previous bar to calculate the new position for the note in the new BPM. You can loop through all of the notes in the .mboy file and use this equation to calculate the new position for each note. Then, you can update the position for each note in the file with the new calculated position.

Here is an example of how you can use this equation to change the speed of the notes in a .mboy file:

// Define the original BPM and the new BPM
const oldBpm = 120;
const newBpm = 150;

// Loop through all of the notes in the .mboy file
for (const note of mboyFile.notes) {
  // Calculate the new position for the note using the equation
  const newPosition = note.position * (newBpm / oldBpm);
  
  // Update the position of the note in the file with the new position
  note.position = newPosition;
}

// Save the updated .mboy file
mboyFile.save();

This code will loop through all of the notes in the .mboy file and calculate the new position for each note using the equation. Then, it will update the position of each note in the file with the new calculated position and save the updated file. This should allow you to change the speed of the notes in the file without changing the speed of the audio.

  • Related