Tool Terraria Midi Player - Play songs through Terrarian instruments

trigger_segfault

Spazmatism
B618e8x.png

Terraria Midi Player is a music player for Terrarian instruments such as the Harp and Bell. The program works by taking control of the mouse to click on the screen at the right coordinates to produce the correct notes as the midi plays. The program comes with a set of global hotkeys that can be pressed while focused on Terraria to force-stop the song or close Terraria Midi Player. The program will also force focus on Terraria when you start the song to avoid causing problems by clicking in unknown places. See the Wiki for all information available on Terraria Midi Player.


(Playing Through the Fire and Flames)
T6tWlQB.gif


gFEWO1C.png


Features

~ Load Midis and play them within Terraria ~
~ Automatically attempts to fit notes within Terraria's two octaves ~
~ Ability to control where Magical Harp projectiles are aimed ~
~ Adjusts for mount height offsets ~
~ Automatically stays focused on Terraria while playing songs in order to avoid accidental clicks ~
~ Connect with others hosting from their Terraria Midi Player to sync songs for a performance ~
~ See more features here ~

Requirements

.NET Framework 4.5.2 | Windows 7 or later
Terraria for PC | Terraria zoom setting must be at 100% (under v1.4)

Downloads: v1.1.0.2

TerrariaMidiPlayer-1.1.0.2.exe
(The main executable. Dlls in the previous downloads are no longer required)
MidiSamples-1.0.zip
(A selection of midis playable without use-time modifications)
Terraria Item Modifier | Terraria Tweaker 2
(Different patches that allow item customization in order to decrease the use-time of instruments)

~ Previous downloads can be found at the bottom of the page ~

gFEWO1C.png


Preview
Pihs8cx.png

Wiki | Credits | Image Album | Source Code

gFEWO1C.png


Video Previews

(Below is a 3-person performance of Link's Awakening's Tal Tal Heights, and Miku Hatsune's Shake It!)


gFEWO1C.png


⬅ Other Information

v1.1.0.2
  • Fixed certain Midi files with Ppqn sequence type failing to load due to division rate.
v1.1.0.1
  • Midi playback is now stopped less often from UI events.
v1.1.0.0
  • Added support for ABC notation files.
  • Added piano mode where you can now preview how midis would sound
    without playing them in Terraria.
  • Piano mode can optionally not wrap or skip notes so you can hear what
    the midi is supposed to sound like.
  • Can now optionally view original track names.
  • Can now optionally disable mount keybind while talking. (Keeps track
    of enter being pressed)
  • Added track graph window with tons of features to facilitate midi
    customization.
  • Can now specify multiple Terraria executable names to check the
    process list for.
  • Added file drop support to the midi list.
  • Every required file and dll is now embedded into the executable.
  • Fixed a bug where disabling a track would temporarily revert its name
    to its track number.
  • A bit of code refactoring.
v1.0.1.0
  • Lots of code refactoring so there may be a few new bugs. If there's any major issues then try using the previous release.
  • Fixed a bug where midis would act strangely if their tempo was never defined in the file.
  • Tracks can now be named
v1.0.0.1
  • Can now specify the name of your Terraria executable in order for Terraria Midi Player to locate its process.
  • Default close keybind is now NumPad+ or Page Up if you don't have a numpad.
  • Fixed some midi tracks not loading because they shared the same channel as another track.
  • Fixed default Checks value being 0 instead of 20.
  • Keybinds now work properly when focused in Terraria before playing a song.
  • Syncing host and client should be a bit less glitchy now.
  • Sync client should now tell you if your username was taken or password incorrect instead of saying failed to login.
  • Sync host now tells you how long until playback starts.
  • Can now cancel the delayed play midi used with syncing by pressing stop.
  • Playback buttons now properly perform the same action as the keybinds when acting as the sync host.
  • Possibly fixed program crashing instead of showing an error window
v1.0.0.0

The first major release of Terraria Midi player with all the features you need to rock out to some midis in Terraria. Also comes with a new finalized UI, a playback UI, a keybind editor, and a syncing feature for multi-person performances (Experimental).
 
Last edited:
This is pretty cool. Although not the most useful, it is certainly fun!
How long did it take you to make this?

It took about 20 days to get it to the point it's at today. I started with scripted songs programmatically entered in and then shifted over to midis once I got the playback down. I'll admit though, half the time was spent screwing around with the tool and playing midis. However it was pretty beneficial since it helped me uncover most of the bugs.
 
can i putt other midis into the midi player?

Yup, you can load any midis you want to play into the program. The main issue with playing any midi is that most aren't suitable for playback in Terraria. By this I mean either the octave adjustment makes it sound off or notes are too fast a and skipped or multiple different notes are played at once.

I'd highly recommend editing any midis you want to play in MidiEditor if they don't sound correct from the get go.

I'm also planning on adding support for ABC files soon too, like what's used in Starbound.
 
v1.1.0.0: The first major version release is here!

With this we have the addition of ABC Notation support, a piano mode to test playback within the program instead of in Terraria, and the new Track Graph window to help visualize how the program modifies the midi in order to be playable in Terraria.

ZmzhU8n.png
 
How to convert mp3 to midi/mid i tried online websites but when i try to place it in the Terraria Midi player it doesn't work

Unfortunately converting to midi, whether possible or not, will never produce good results unless the original track is relatively clean and minimal. For example: Black Midis are usually the output and 100% unplayable in Terraria due to the number of notes compressed into one moment.

If you want a midi, then your best bet is to find an existed one that has already been manually constructed by something.
 
Where to download other midis that work for this?

There really isn't any designated place to find midis that naturally work with this. Out of a hundred midis I looked at while making this, only a couple sounded natural when played without modification. Basically, if you want to play a song in Terraria, you'll almost always need to do the work yourself to make it sound nice.

Now I plan on making some sort of guide to help people with editing midis into a playable format as a user on YouTube recently requested it, so I'll keep you updated on that. But for now I'll layout some general tips and tricks.

Forwarning:
Improving midis often requires a bit of knowledge about music, if you have musical experience, then this information will be much easier to process. I'm no expert on music so my explanations are pretty lacking. I do have a friend who works in that field though, so they may be able to help in writing a proper guide.

Important Information:
Semitone/Halfstep: The interval between notes.
Octave: A range of 12 semitones, From C to B. (Terraria supports 2 Octaves + an extra high C). A C note at octave 4 (C4) will sound the same as a C note at other octaves, besides the change in overall pitch. This does not mean that which octave it's on is irrelevant though.
Notes: C, C#, D, D#, E, F, F#, G, G#, A, A#, B (The same as: C, D♭, D, E♭, E, F, G♭, G, A♭, A, B♭, B)
Notes usually are numbered with their octave. For example: C4, or B♭6.

Editing:
I personally used Midi Editor to fix up and prepare my midis. This one works well for this purpose and it's free.
I don't have the time to write a comprehensive guide on how to use Midi Editor but there may be some helpful forums posts explaining anything you have trouble with.

Editing Tips & Tricks:
Note Overlapping: The biggest problem with playing midis is the fact that multiple notes very often overlap each other in the timeline. Most of the time these notes are in the same octave, so picking one to remove is as easy as choosing the one that's in the octave range you plan on using. The other situation is when the song is playing a chord, in this case, you'll have to listen to the chord and each individual note, and then decide which one sounds closest to what the original sounded like.

Octave Wrapping: The next important problem to tackle is octave wrapping. If a note is outside the 2 octave range of Terraria's instruments, Terraria midi player will bring it into the range by raising or lowering it X octaves until it's in range. This is helpful as, it removes the need to change the octave yourself, hover it does not always produce optimal results. For example, when I was editing Tal Tal Heights, I found that one part of the song started going too high halfway through. Because only a few notes were out of range, the octave wrapping made this part sound strange. What I did was take the entire second half of the part of the song and lower it one octave so it sounded better with only an initial instance of wrapping. See example here at 1:16.

Long Notes: In Terraria you can not hold a note, or continue to play the note for a duration of time. There aren't many cases where long notes make the sound sound worse when playing it, but if there's a long period where a single note is played and nothing else, you may want to try repeating the note over the duration. When you repeat the note, it's important to match it to the time signature of the song. This isn't necessarily displayed anywhere, but it can be determined based on how often the major notes are hit during a single measure. A common example is 4/4 notes quarter per measure.

Multiple Tracks: Often times, midis come packed with multiple tracks that each play a different part of the song. Usually, you'll want to play the melody which is the main part of the song (it's not guaranteed that this is packed into a single track). The harmony on the other hand, is the background portion of the song that adds life to it. This is where playing music with multiple people is helpful (but hard to organize). It's not always impossible to play both the melody and harmony at the same time if the notes give room for both to be played.

Percussion Tracks: Tracks that play sound effects such as drums or symbols are usually completely unnecessary for Terraria Midi Player, it's recommended you completely remove these tracks so that the program does not attempt to play these notes.
 
я когда нажимаю конект сервер ложится у всех проверено

[Translated with help of friend]

1) Порт, который ты создаешь и с которым синхронизируешься должен отличаться от порта самого сервера.
Это разные службы, которые не должны препятствовать работе друг друга.

2) Возможно эта проблема связана с системой безопасности выделенной ваниллы, TShock'ом или TModLoader сервером.
Эти сервера не подтверждают тот факт, что подключение происходит именно к клиенту Террарии. Можешь сказать
на каком типе сервера это произошло? Я уже понял, что это как-то связано с TShock'ом.

Я отправлю багрепорт определенным людям, как только узнаю, с каким именно типом сервера произошла проблема.
Это довольно серьезная проблема.
 
Some unfortunate news for Terraria Midi Player. I've found the source of the issue being reported with occasional off-sounding note pitch during playback. In short...

Half of all playable notes have been snapped from existence. :dryadcry: (however the range is still 2 octaves)

More specifically, notes are being clipped to 6th's of an octaves' range, allowing for easy playback by hand. Personally I like this decision, as it really does make hitting your intended note easy, meanwhile allowing the full 12-notes per octave drastically decreases accuracy. But of course this prevents other standard notes from being playable at all, granted, my knowledge still isn't fully up-to-date with the instrument changes besides the new musical items. Not all is bad news though...

Interesting Improvements to Instruments in Terraria 1.4:
~ Zoom settings no longer affect the pitch of note playback 🎉 ~
~ The entire process of handling musical instruments in-code is much cleaner (much less hardcoded magic) ~
~ The area in code causing note pitch clipping to 6th's is very easily modifiable for patchers ~
~ Note clipping is done before reporting to the server, so it's not client side! 🎊 ~
~ With the number of advanced settings being added to config.json, we may get one to change this ~

Below is the list of notes affected by the current system.

C4 low C : center of player
╳ C♯4 (D♭4)
D4​
╳ D♯4 (E♭4)
E4​
╳ F4
F♯4 (G♭4)​
╳ G4
G♯4 (A♭4)​
╳ A4
A♯4 (B♭4)​
╳ B4

C5 middle C : 1/4 screen height from player
╳ C♯5 (D♭5)
D5​
╳ D♯5 (E♭5)
E5​
╳ F5
F♯5 (G♭5)​
╳ G5
G♯5 (A♭5)​
╳ A5
A♯5 (B♭5)​
╳ B5

C6 high C : >= 1/2 screen height from player

Instrument playback in Source Code

Notes are being clipped to one of 12 values (6 per octave), before we had a range of 24 semitones (12 per octave), Note there were no restrictions or clipping pre-1.4, but 12-semitones per octave is what is normally used.
The change in note clipping is all controlled through the variable Terraria.Player.musicNotes.

C#:
/** public static int Terraria.Player.musicNotes */

// Patching this value to 12 is the optimal solution, it is not changed at runtime
public static int musicNotes = 6;
C#:
/** private void Terraria.Player.ItemCheck_PlayInstruments(Item item) */

// pitch is calculated as usual (but screenHeight now has zoom settings stripped away)
float range = Math.Clamp( (mouseDistance / (screenHeight / 2f)) ,  0f, 1f);
// move from range [0,1] -> pitch [-1,1]  (for 1 octave down min, or 1 up down max :  2 octaves total range)
float pitch = Math.Clamp( (range * 2f - 1f) ,  -1f, 1f);

// Clamp pitch to one of six values (positive or negative) (12 total)
pitch  = (float)Math.Round((double)(pitch * (float)Player.musicNotes));
pitch /= (float)Player.musicNotes;

// Something new
Main.musicPitch = pitch;

In short, this was all more concerning on first discovery, but its clear things were well-designed in 1.4 in terms of flexibility (even if not supported yet).
Terraria Midi Player will not be getting an update to work-around the note clipping, (there really isn't any solution that could solve issue, octaves can be wrapped and sound close enough, but missing notes don't have that luxury). Terraria Midi Player will more likely be updated to fix this via other means.

I plan on waiting to see what happens with instruments going forwards. But a patcher to change the Terraria.Player.musicNotes value is a very likely possibility. It's already been confirmed to work with a quick one-line modification using dnSpy (a tool for modifying programs written in .NET, like C#) `:happy:

Note: That if you have a song without any missing notes, then everything will still work fine as usual. Actually, a setting to ignore missing notes or reprioritize (when overlapping with other notes) may be a workable solution for a future update.
 
Last edited:
Back
Top Bottom