alda-lang / alda-core

The core machinery of Alda
80 stars 26 forks source link

track-volume in MIDI output #75

Closed truj closed 4 years ago

truj commented 4 years ago

The handling of the track-volume attribute should be changed.

Currently it's translated into a channel volume MIDI message (MSB Controller 7). But it should be an expression message (MSB Controller 11). cf. https://www.midi.org/specifications-old/item/table-3-control-change-messages-data-bytes-2

Reason: Channel volume should not be used inside of a MIDI sequence. It should be used for mixing purposes during playback. E.g. by a mixing console. Or by a MIDI player. The correct equivalent for a MIDI sequence is an expression message.

Second problem: The channel volume message is sent together with every single note-ON message, no matter if there was any track-volume attribute change or not. That creates much more messages than necessary.

Reproduce:

The volume is not reduced at all because the channel volume messages re-adjust the channel volume all over again.

daveyarwood commented 4 years ago

Just to be sure it's clear:

Alda has two similarly named attributes, volume and track-volume.

volume translates into the velocity of each individual note, i.e. how soft/hard to hit the key. This is encoded into every Note On message as a 7-bit value.

track-volume translates into a Channel Volume (7) message.

volume should typically be used for dynamic variation, and track-volume should typically be used for mixing purposes (although volume can also be used for mixing purposes, and that's what I tend to do)


It is true that we're sending a Channel Volume message for every single note, which, as you pointed out, is very inefficient. It's been on my mind to fix that for quite a while now... hopefully I'll get around to it at some point! :sweat_smile:

I wasn't aware of the Expression (11) message. I'll have to think about that and how it relates to Alda.

My gut feeling is that you're right; perhaps track-volume should correspond to Expression instead of Channel Volume, and Alda should never set Channel Volume, as (if I'm understanding correctly) if you were to play a MIDI file exported from Alda in another program like Midica, you would lose the ability to set the Channel Volume yourself because the MIDI sequence would also be setting the Channel Volume during playback.

Do you think it might be useful if Alda exposed the ability to send both kinds of messages, Expression and Channel Volume? We could perhaps add a new attribute (maybe called channel-volume) that allows you to set it if you really want to. But based on the context here, it sort of feels like something you just shouldn't do in an Alda score, as it's data that maybe should never be part of a MIDI sequence?

truj commented 4 years ago

Yes, I know the difference between the volume and track-volume attribute.

I would not offer an attribute called channel-volume. Why should you offer an attribute that people should not use? Just replace the status byte 7 --> 11. Should be trivial to fix.

The second problem is maybe harder to fix. Depends on the architecture.

By the way, did I choose the right project for this issue, or should I have chosen alda-sound-engine-clj?

daveyarwood commented 4 years ago

I would not offer an attribute called channel-volume. Why should you offer an attribute that people should not use? Just replace the status byte 7 --> 11. Should be trivial to fix.

That's what I'm thinking too. I just wanted to carefully consider whether it might be useful to still offer a way to generate Channel Volume messages. The more I think about it, the more I don't think it's necessary, so we should just use status byte 11 instead of 7 and make sure it still works.

The second problem is maybe harder to fix. Depends on the architecture.

I haven't had a close look yet, but I don't think it should be too hard to fix. I think I might be inclined to leave it the way it is in Alda v1, though, and fix it in Alda v2.

By the way, did I choose the right project for this issue, or should I have chosen alda-sound-engine-clj?

It should go in alda-sound-engine-clj. I'm actually going to close this issue and open two new ones: