Search This Blog

2025/02/09

Install Mobile Ads SDK (iOS) by cocoapods

Navigate to your project folder

Open a terminal and go to your project directory:

cd /path/to/your/project


Initialize the Podfile

Run the following command to create a Podfile:

pod init


Open the Podfile

Use a text editor or open it directly in the terminal:

open Podfile


Add the Google Mobile Ads SDK

Inside the Podfile, add this line under target 'YourApp' do:

pod 'Google-Mobile-Ads-SDK', '11.5.0'


Save and close the file

Install the pods with repo update, run the following command:

pod install --repo-update


Open the project using the generated .xcworkspace file

open YourProject.xcworkspace

2025/02/08

Install Homebrew and CocoaPods in xcode 14

I have an old MacBook (Early 2015) running macOS Monterey 12.7.6.

When I try to install CocoaPods via the command line, I get the following error:

securerandom requires Ruby version >= 3.1.0. The current Ruby version is 2.6.10.210.

I cannot update Ruby using gem update --system because macOS does not allow it.

So, I decided to use Homebrew to install CocoaPods instead.


Installing Homebrew

First, I checked if Homebrew was installed by running:

brew -v

However, this returned an error:

-bash: brew: command not found

To install Homebrew, I used the following command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

During installation, I had to enter my password a few times.

Once the installation was complete, I verified it by running:

brew -v

The output confirmed that Homebrew was installed:

Homebrew 4.4.20

Installing CocoaPods

Now that Homebrew is installed, I was able to install CocoaPods using:

brew install cocoapods

Additionally, I was able to update Ruby and then use Ruby to install CocoaPods.

2025/01/17

music_generator by Python

Install

pip install numpy

pip install mido

pip install soundfile

pip install streamlit


Code
import numpy as np
import soundfile as sf
import streamlit as st
from mido import Message, MidiFile, MidiTrack
import random

def create_random_melody(style, instrument, duration=180):
    """
    Generates a random melody and saves it as a MIDI file.

    Args:
        style (str): The selected music style ('Calm', 'Bright', 'Mysterious').
        instrument (str): The selected instrument ('Piano', 'Violin', 'Flute', etc.).
        duration (int): Duration of the melody in seconds.

    Returns:
        str: Filename of the generated MIDI file.
    """
    midi_filename = f"{style}_{instrument}_music.mid"
    mid = MidiFile()
    track = MidiTrack()
    mid.tracks.append(track)

    if style == "Calm":
        notes = [60, 62, 64, 65, 67, 69, 71, 72]  # C Major Scale
    elif style == "Bright":
        notes = [72, 74, 76, 77, 79, 81, 83, 84]  # Higher octave C Major Scale
    elif style == "Mysterious":
        notes = [60, 63, 65, 68, 70, 73, 75, 78]  # Suspenseful scale
    else:
        notes = [60, 62, 64, 67, 69]  # Default to C Pentatonic Scale

    total_ticks = 0
    ticks_per_note = 480

    while total_ticks < duration * 480:
        note = random.choice(notes)
        velocity = random.randint(50, 100)
        track.append(Message('note_on', note=note, velocity=velocity, time=0))
        track.append(Message('note_off', note=note, velocity=velocity, time=ticks_per_note))
        total_ticks += ticks_per_note

    mid.save(midi_filename)
    return midi_filename

# Streamlit App
def main():
    st.title("Random Music Generator")

    # User inputs
    style = st.selectbox("Choose a music style:", ["Calm", "Bright", "Mysterious"])
    instrument = st.selectbox("Choose an instrument:", ["Piano", "Violin", "Flute", "Guitar"])
    duration = st.slider("Select duration (seconds):", min_value=30, max_value=180, step=30, value=90)
    file_format = st.selectbox("Select file format:", ["MIDI"])

    if st.button("Generate Music"):
        st.write(f"Generating {style} music with {instrument} for {duration} seconds...")

        if file_format == "MIDI":
            midi_filename = create_random_melody(style, instrument, duration)
            st.success("MIDI file generated successfully!")

            # Provide MIDI download link
            with open(midi_filename, "rb") as midi_file:
                st.download_button(
                    label="Download MIDI File",
                    data=midi_file,
                    file_name=midi_filename,
                    mime="audio/midi"
                )

if __name__ == "__main__":
    main()


RUN

streamlit run music_generator.py