Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PortSpec be chosen at runtime #1

Merged
merged 3 commits into from
Oct 8, 2017
Merged

Make PortSpec be chosen at runtime #1

merged 3 commits into from
Oct 8, 2017

Conversation

Javyre
Copy link
Contributor

@Javyre Javyre commented Oct 8, 2017

No description provided.

@Javyre
Copy link
Contributor Author

Javyre commented Oct 8, 2017

The bit that is driving me insane:
https://github.com/Snowlabs/Jamyx/blob/develop/src/jamyxer.rs#L31

@Javyre
Copy link
Contributor Author

Javyre commented Oct 8, 2017

Related issue:
RustAudio/rust-jack#73

@Javyre
Copy link
Contributor Author

Javyre commented Oct 8, 2017

I know that the Box thing doesnt work, and I understand why.
But this is just one of my many attempts at making the spec chosen at runtime

@Javyre
Copy link
Contributor Author

Javyre commented Oct 8, 2017

I fixed it... kind of...
This isnt what i wanted but it seems to be the only solution.
There is a lot of code repetition. Im basically writing the same function twice and this is really bad

@Javyre
Copy link
Contributor Author

Javyre commented Oct 8, 2017

🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉
found an elegant solution!

#[derive(Clone, Copy)]
enum AnySpec {
    AudioOut,
    AudioIn,
}

unsafe impl j::PortSpec for AnySpec {
    fn jack_port_type(&self) -> &str {
        match self {
            &AnySpec::AudioIn => {
                static ispec: j::AudioInSpec = j::AudioInSpec;
                ispec.jack_port_type()
            },
            &AnySpec::AudioOut => {
                static ospec: j::AudioOutSpec = j::AudioOutSpec;
                ospec.jack_port_type()
            },
        }
    }

    fn jack_flags(&self) -> j::PortFlags {
        match self {
            &AnySpec::AudioIn => j::AudioInSpec.jack_flags(),
            &AnySpec::AudioOut => j::AudioOutSpec.jack_flags(),
        }
    }

    fn jack_buffer_size(&self) -> libc::c_ulong {
        match self {
            &AnySpec::AudioIn => j::AudioInSpec.jack_buffer_size(),
            &AnySpec::AudioOut => j::AudioOutSpec.jack_buffer_size(),
        }
    }
}

@Javyre
Copy link
Contributor Author

Javyre commented Oct 8, 2017

Preparing commit...

@Javyre Javyre changed the title Impl Jamyxer Make PortSpec be chosen at runtime Oct 8, 2017
@Javyre Javyre merged commit 5ca285c into master Oct 8, 2017
@Javyre Javyre deleted the develop branch October 8, 2017 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant