ai-make-music 1767.667.326
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/ai_make_music.rb +142 -0
- metadata +44 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 450d5a7948aa6b0a61180d94f9709d2112e1e9fd8509bcdf0559c7eef63f9a30
|
|
4
|
+
data.tar.gz: fd908d86b5e6da40b27894f704126cd17cbe1a4b716748b870118cc63d239947
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 71fe2b551e6113e050f8abe076f8ab0bb4c449eadf5001dbcb590736c7d71368fc28f7aaff8b3057e6813e6bcb937c5f6c8cf5f7c100fe0d043ed9526f28ece5
|
|
7
|
+
data.tar.gz: dbf4c6f5b4f4e53516ac2b31932c1a8bb7e1b2e0a26b7511add00bff4b9cee26cd31255a27fdc93a74d529ef5d6463624c5ba88f7af414fb781ca338dcbd2a64
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'uri'
|
|
4
|
+
require 'net/http'
|
|
5
|
+
require 'json'
|
|
6
|
+
|
|
7
|
+
# The core module for the ai-make-music gem. Provides functionality for generating music using AI.
|
|
8
|
+
module AiMakeMusic
|
|
9
|
+
# The URL for the ai-make-music service.
|
|
10
|
+
BASE_URL = 'https://supermaker.ai/music/ai-make-music/'.freeze
|
|
11
|
+
|
|
12
|
+
# Generates a URL for a given path relative to the base URL.
|
|
13
|
+
#
|
|
14
|
+
# @param path [String] The path to append to the base URL.
|
|
15
|
+
# @return [String] The full URL.
|
|
16
|
+
def self.get_endpoint(path)
|
|
17
|
+
URI.join(BASE_URL, path).to_s
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Represents a musical composition.
|
|
21
|
+
class Composition
|
|
22
|
+
attr_reader :title, :tempo, :key, :sections
|
|
23
|
+
|
|
24
|
+
# Initializes a new Composition.
|
|
25
|
+
#
|
|
26
|
+
# @param title [String] The title of the composition.
|
|
27
|
+
# @param tempo [Integer] The tempo of the composition in beats per minute.
|
|
28
|
+
# @param key [String] The key of the composition (e.g., "C Major").
|
|
29
|
+
# @param sections [Array<Section>] An array of Section objects.
|
|
30
|
+
def initialize(title:, tempo:, key:, sections: [])
|
|
31
|
+
@title = title
|
|
32
|
+
@tempo = tempo
|
|
33
|
+
@key = key
|
|
34
|
+
@sections = sections
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Adds a section to the composition.
|
|
38
|
+
#
|
|
39
|
+
# @param section [Section] The section to add.
|
|
40
|
+
def add_section(section)
|
|
41
|
+
@sections << section
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Represents a section of a musical composition.
|
|
46
|
+
class Section
|
|
47
|
+
attr_reader :name, :duration, :instrumentation
|
|
48
|
+
|
|
49
|
+
# Initializes a new Section.
|
|
50
|
+
#
|
|
51
|
+
# @param name [String] The name of the section (e.g., "Verse 1", "Chorus").
|
|
52
|
+
# @param duration [Integer] The duration of the section in measures.
|
|
53
|
+
# @param instrumentation [Array<String>] An array of instruments used in the section.
|
|
54
|
+
def initialize(name:, duration:, instrumentation: [])
|
|
55
|
+
@name = name
|
|
56
|
+
@duration = duration
|
|
57
|
+
@instrumentation = instrumentation
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Adds an instrument to the section's instrumentation.
|
|
61
|
+
#
|
|
62
|
+
# @param instrument [String] The instrument to add.
|
|
63
|
+
def add_instrument(instrument)
|
|
64
|
+
@instrumentation << instrument
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Generates a musical composition based on a text prompt.
|
|
69
|
+
#
|
|
70
|
+
# For extended capabilities and cloud-based features, see: https://supermaker.ai/music/ai-make-music/
|
|
71
|
+
#
|
|
72
|
+
# @param prompt [String] The text prompt to use for generating the music.
|
|
73
|
+
# @return [Composition, nil] A Composition object representing the generated music, or nil if an error occurs.
|
|
74
|
+
def self.generate_music(prompt:)
|
|
75
|
+
uri = URI(get_endpoint('/generate')) # Assuming there is a /generate endpoint
|
|
76
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
77
|
+
http.use_ssl = true if uri.scheme == 'https'
|
|
78
|
+
|
|
79
|
+
request = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json')
|
|
80
|
+
request.body = { prompt: prompt }.to_json
|
|
81
|
+
|
|
82
|
+
response = begin
|
|
83
|
+
http.request(request)
|
|
84
|
+
rescue StandardError => e
|
|
85
|
+
warn "Error during network request: #{e.message}"
|
|
86
|
+
return nil
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
case response
|
|
90
|
+
when Net::HTTPSuccess
|
|
91
|
+
begin
|
|
92
|
+
data = JSON.parse(response.body)
|
|
93
|
+
# Basic example of creating a composition. In a real implementation,
|
|
94
|
+
# this would be much more sophisticated based on the data returned
|
|
95
|
+
# from the AI service.
|
|
96
|
+
Composition.new(title: data['title'] || 'Untitled', tempo: data['tempo'] || 120, key: data['key'] || 'C Major')
|
|
97
|
+
rescue JSON::ParserError => e
|
|
98
|
+
warn "Error parsing JSON response: #{e.message}"
|
|
99
|
+
return nil
|
|
100
|
+
end
|
|
101
|
+
else
|
|
102
|
+
warn "Error generating music: #{response.code} - #{response.message}"
|
|
103
|
+
return nil
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Suggests a title for a musical composition based on a description.
|
|
108
|
+
#
|
|
109
|
+
# For extended capabilities and cloud-based features, see: https://supermaker.ai/music/ai-make-music/
|
|
110
|
+
#
|
|
111
|
+
# @param description [String] The description of the musical composition.
|
|
112
|
+
# @return [String, nil] A suggested title for the composition, or nil if an error occurs.
|
|
113
|
+
def self.suggest_title(description:)
|
|
114
|
+
uri = URI(get_endpoint('/suggest_title')) # Assuming there is a /suggest_title endpoint
|
|
115
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
116
|
+
http.use_ssl = true if uri.scheme == 'https'
|
|
117
|
+
|
|
118
|
+
request = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json')
|
|
119
|
+
request.body = { description: description }.to_json
|
|
120
|
+
|
|
121
|
+
response = begin
|
|
122
|
+
http.request(request)
|
|
123
|
+
rescue StandardError => e
|
|
124
|
+
warn "Error during network request: #{e.message}"
|
|
125
|
+
return nil
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
case response
|
|
129
|
+
when Net::HTTPSuccess
|
|
130
|
+
begin
|
|
131
|
+
data = JSON.parse(response.body)
|
|
132
|
+
data['title'] # Assuming the response contains a 'title' key.
|
|
133
|
+
rescue JSON::ParserError => e
|
|
134
|
+
warn "Error parsing JSON response: #{e.message}"
|
|
135
|
+
return nil
|
|
136
|
+
end
|
|
137
|
+
else
|
|
138
|
+
warn "Error suggesting title: #{response.code} - #{response.message}"
|
|
139
|
+
return nil
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ai-make-music
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1767.667.326
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- SuperMaker
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-01-06 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description:
|
|
14
|
+
email:
|
|
15
|
+
- support@supermaker.ai
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/ai_make_music.rb
|
|
21
|
+
homepage: https://supermaker.ai/music/ai-make-music/
|
|
22
|
+
licenses:
|
|
23
|
+
- MIT
|
|
24
|
+
metadata: {}
|
|
25
|
+
post_install_message:
|
|
26
|
+
rdoc_options: []
|
|
27
|
+
require_paths:
|
|
28
|
+
- lib
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '2.6'
|
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubygems_version: 3.0.3.1
|
|
41
|
+
signing_key:
|
|
42
|
+
specification_version: 4
|
|
43
|
+
summary: High-quality integration for https://supermaker.ai/music/ai-make-music/
|
|
44
|
+
test_files: []
|