<commit_before>//
//  yas_audio_ios_session.h
//

#pragma once

#include <TargetConditionals.h>

#if TARGET_OS_IPHONE

#include <cpp_utils/yas_result.h>

#include "yas_audio_interruptor.h"
#include "yas_audio_ios_device_session.h"
#include "yas_audio_ptr.h"

namespace yas::audio {
struct ios_session : ios_device_session, interruptor {
    enum class category {
        ambient,
        solo_ambient,
        playback,
        record,
        play_and_record,
        multi_route,
    };

    using activate_result_t = result<std::nullptr_t, std::string>;

    [[nodiscard]] double sample_rate() const override;

    void set_preferred_sample_rate(double const);
    void set_preferred_io_buffer_frames(uint32_t const);

    [[nodiscard]] uint32_t output_channel_count() const override;
    [[nodiscard]] uint32_t input_channel_count() const override;
    [[nodiscard]] bool is_input_available() const;

    [[nodiscard]] bool is_active() const;
    [[nodiscard]] activate_result_t activate();
    [[nodiscard]] activate_result_t reactivate();
    void deactivate();

    bool is_interrupting() const override;

    [[nodiscard]] enum category category() const;
    void set_category(enum category const);

    [[nodiscard]] chaining::chain_unsync_t<device_method> device_chain() const override;
    [[nodiscard]] chaining::chain_unsync_t<interruption_method> interruption_chain() const override;

    [[nodiscard]] static ios_session_ptr const &shared();

   private:
    class impl;

    bool _is_active = false;
    bool _is_interrupting = false;
    enum category _category;
    double _preferred_sample_rate = 44100.0;
    uint32_t _preferred_io_buffer_frames = 1024;

    std::unique_ptr<impl> _impl;
    chaining::notifier_ptr<device_method> _device_notifier;
    chaining::notifier_ptr<interruption_method> _interruption_notifier;

    ios_session();

    activate_result_t _set_category();
    activate_result_t _apply_sample_rate();
    activate_result_t _apply_io_buffer_duration();
    activate_result_t _set_active();

    void _set_interrupting_and_notify(bool const);
    void _setup_interrupting();
    void _dispose_interrupting();
};
}  // namespace yas::audio

namespace yas::audio {
[[nodiscard]] bool is_output_category(enum audio::ios_session::category const);
[[nodiscard]] bool is_input_category(enum audio::ios_session::category const);
}  // namespace yas::audio

#endif
<commit_msg>category options<commit_after>//
//  yas_audio_ios_session.h
//

#pragma once

#include <TargetConditionals.h>

#if TARGET_OS_IPHONE

#include <cpp_utils/yas_flagset.h>
#include <cpp_utils/yas_result.h>

#include "yas_audio_interruptor.h"
#include "yas_audio_ios_device_session.h"
#include "yas_audio_ptr.h"

namespace yas::audio {
struct ios_session : ios_device_session, interruptor {
    enum class category {
        ambient,
        solo_ambient,
        playback,
        record,
        play_and_record,
        multi_route,
    };

    enum class category_option : std::size_t {
        mix_with_others,
        duck_others,
        allow_bluetooth,
        default_to_speaker,
        interrupt_spoken_audio_and_mix_with_others,
        allow_bluetooth_a2dp,
        allow_air_play,

        count,
    };

    using category_options_t = flagset<category_option>;
    using activate_result_t = result<std::nullptr_t, std::string>;

    [[nodiscard]] double sample_rate() const override;

    void set_preferred_sample_rate(double const);
    void set_preferred_io_buffer_frames(uint32_t const);

    [[nodiscard]] uint32_t output_channel_count() const override;
    [[nodiscard]] uint32_t input_channel_count() const override;
    [[nodiscard]] bool is_input_available() const;

    [[nodiscard]] bool is_active() const;
    [[nodiscard]] activate_result_t activate();
    [[nodiscard]] activate_result_t reactivate();
    void deactivate();

    bool is_interrupting() const override;

    [[nodiscard]] enum category category() const;
    void set_category(enum category const);

    [[nodiscard]] chaining::chain_unsync_t<device_method> device_chain() const override;
    [[nodiscard]] chaining::chain_unsync_t<interruption_method> interruption_chain() const override;

    [[nodiscard]] static ios_session_ptr const &shared();

   private:
    class impl;

    bool _is_active = false;
    bool _is_interrupting = false;
    enum category _category;
    double _preferred_sample_rate = 44100.0;
    uint32_t _preferred_io_buffer_frames = 1024;

    std::unique_ptr<impl> _impl;
    chaining::notifier_ptr<device_method> _device_notifier;
    chaining::notifier_ptr<interruption_method> _interruption_notifier;

    ios_session();

    activate_result_t _set_category();
    activate_result_t _apply_sample_rate();
    activate_result_t _apply_io_buffer_duration();
    activate_result_t _set_active();

    void _set_interrupting_and_notify(bool const);
    void _setup_interrupting();
    void _dispose_interrupting();
};
}  // namespace yas::audio

namespace yas::audio {
[[nodiscard]] bool is_output_category(enum audio::ios_session::category const);
[[nodiscard]] bool is_input_category(enum audio::ios_session::category const);
}  // namespace yas::audio

#endif

{'fraction_non_alphanumeric': 0.09959545366981314, 'fraction_numerical': 0.00712772105567328, 'mean_word_length': 4.576799140708915, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2754581', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1662, 'n_words': 332}