Ableton-V
Ableton-V is a CLI tool built for fun.
It is an exploration of Ableton's file formats and an excuse to use Rust for intensive string parsing purposes.
I didn't go into this project expecting to build it all the way out, but I wanted to experiment with treating Ableton sessions as raw XML as I had seen this mentioned on a forum somewhere. It turns out parsing them as XML in Rust was very doable, and I was able to extract metadata such as track names/numbers, sample locations and much more.
Rust's From trait is an example of a pattern that makes the language suited to this task. Being able to define a struct in a way that makes sense for the program and implementing the From trait for a reference to an XML event made it very simple to parse out different types of XML chunk in a dynamic way.
impl<'a> From<&XmlEvent> for ParserOutput<'a> {
fn from(event: &XmlEvent) -> ParserOutput<'a> {
match event {
XmlEvent::StartElement { name, .. } => match name.local_name.as_str() {
"Ableton" => ParserOutput::Ableton(Ableton::from(event)),
"LiveSet" => ParserOutput::LiveSet(LiveSet::from(event)),
"Tracks" => ParserOutput::TracksStart(event.clone()),
_ => { // More cases could be added above to parse out different events from the xml
ParserOutput::UnchangedChunk(event.clone())
}
},
XmlEvent::EndElement { name, .. } => match name.local_name.as_str() {
"Ableton" => ParserOutput::AbletonEnd(event.clone()),
"LiveSet" => ParserOutput::LiveSetEnd(event.clone()),
"Tracks" => ParserOutput::TracksEnd(event.clone()),
_ => ParserOutput::Close(event.clone()),// More cases could be added above to parse out different events from the xml
},
XmlEvent::StartDocument { .. } => ParserOutput::EndDocument,
_ => ParserOutput::None,
}
}
}
As a proof of concept I quite enjoyed exploring this, and unlike MySQL Translate I think Rust was the right choice here. In the future I'd like to build out the ability to diff sessions, and to be able to navigate through session history in the terminal as I can with git if I were to complete this.