Compare commits

...
This repository has been archived on 2024-10-01. You can view files and clone it, but cannot push or open issues or pull requests.

2 Commits

Author SHA1 Message Date
Nikolai Rodionov
aa87ad7538
WIP: Start implementing OAuth 2023-05-31 14:25:42 +02:00
Nikolai Rodionov
918b075b62
WIP: Start writing a first post 2023-05-31 13:22:28 +02:00

View File

@ -0,0 +1,144 @@
---
title: "Developing a Free Alternative for Splice"
date: 2023-05-31T12:05:44+02:00
draft: true
ShowToc: true
cover:
image: "cover.png"
caption: "Developing a Free Alternative for Splice"
relative: false
responsiveImages: false
---
## Intro
I think that almost everybody knows what **Splice** is. Basically, it's just a huge library of sounds and VST presets with some additional sweets. I can't say that I'm not satisfied by Splice, it's an applications that is doing pretty good, until you want to use it on Linux. That's something that I don't understand, (I'm almost sure that )it's an Electron application with and some binary running a gRPC server in a background, that I believe is written in **GO**. Both technologies are working on Linux, so basically, they could have just built a version without promising any real support for that. But they haven't. I've decided to try running it with WINE, but it didn't work. And then I though: There is awesome [freesound](https://freesound.org/), and why wouldn't I use it?
> Freesound is a collaborative database of Creative Commons Licensed sounds. Browse, download and share sounds.
But downloading samples using a browser it not something I'd like to do. I love Splice for their drag-n-drop app. And I've decided to develop one that will work with Freesound.
## Starting the project
I've decided to use Rust and try the [Iced](https://iced.rs/) for the UI.
Here you will find the project git repository: https://git.badhouseplants.net/allanger/frice
Basically, there are two things to do so the MVP is ready
- Make correct API requests to the Freesound
- Create a UI
So the very first thing that I'm doing, I'm initializing a project and creating a very simple **Iced** app using examples
```bh
cargo init
cargo add iced
```
```toml
# Cargo.toml
[package]
name = "frice"
version = "0.1.0"
edition = "2021"
[dependencies]
iced = "0.9.0"
```
```rust
// ./src/main.rs
use iced::{Sandbox, Settings, widget::Container};
fn main() -> Result<(), iced::Error> {
Frice::run(Settings::default())
}
struct Frice {}
impl Sandbox for Frice {
type Message = String;
fn new() -> Self {
Frice {}
}
fn title(&self) -> String {
"Frice".to_string()
}
fn update(&mut self, message: Self::Message) {
println!("Updating")
}
fn view(&self) -> iced::Element<'_, Self::Message> {
Container::new("frice").center_x().center_y().width(iced::Length::Fill).height(iced::Length::Fill).into() }
}
```
### API
And now I want to switch to the API, because the UI without API requests won't be able to do anything. As I see now, I'll need to implement two API calls for the MVP:
1. Search sounds
2. Download a sound
So let's start with the first one. They have a basic example of searching on their [documentation page](https://freesound.org/docs/api/overview.html)
```bash
curl "https://freesound.org/apiv2/search/text/?query=dogs&token=YOUR_API_KEY"
```
*API key can be created here: <https://freesound.org/apiv2/apply>*
So let's create a FreesoundAPI struct and add two methods there
```rust
struct FreesoundAPI {}
impl FreesoundAPI {
fn new() -> Self {
Self {}
}
fn search() {
todo!()
}
fn download() {
todo!()
}
}
```
To create an API call I'll need a token, so I need to add a new field to the `FreesoundAPI struct`
```rust
struct FreesoundAPI {
token: String
}
impl FreesoundAPI {
fn new(token: String) -> Self {
Self { token }
}
...
}
```
I also need a library for making API calls `cargo add reqwest`
```rust
pub(crate) fn search(&self) {
let client = reqwest::blocking::Client::builder().build().unwrap();
let res = client.get("https://freesound.org/apiv2/search/text")
.query(&[("token", self.token.as_str()), ("query", "dogs")])
.send().unwrap();
println!("{:?}", res.text());
}
```
Let's leave it like this for a moment, and try to implement the `download` method. Freesound API sais that we need to use `Oauth` to download sounds. Let's try.
```bash
cargo add oauth2
```